2024-05-14 08:45:41 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2024-07-09 00:04:48 +02:00
|
|
|
import type * as jotai from "jotai";
|
2024-07-03 23:31:02 +02:00
|
|
|
import type * as rxjs from "rxjs";
|
|
|
|
|
2024-05-27 08:05:11 +02:00
|
|
|
declare global {
|
2024-07-19 22:44:32 +02:00
|
|
|
type GlobalAtomsType = {
|
|
|
|
windowId: jotai.Atom<string>; // readonly
|
|
|
|
clientId: jotai.Atom<string>; // readonly
|
|
|
|
client: jotai.Atom<Client>; // driven from WOS
|
|
|
|
uiContext: jotai.Atom<UIContext>; // driven from windowId, activetabid, etc.
|
|
|
|
waveWindow: jotai.Atom<WaveWindow>; // driven from WOS
|
|
|
|
workspace: jotai.Atom<Workspace>; // driven from WOS
|
2024-08-28 03:49:49 +02:00
|
|
|
fullConfigAtom: jotai.PrimitiveAtom<FullConfigType>; // driven from WOS, settings -- updated via WebSocket
|
|
|
|
settingsAtom: jotai.Atom<SettingsType>; // derrived from fullConfig
|
2024-07-19 22:44:32 +02:00
|
|
|
tabAtom: jotai.Atom<Tab>; // driven from WOS
|
|
|
|
activeTabId: jotai.Atom<string>; // derrived from windowDataAtom
|
2024-07-22 22:33:10 +02:00
|
|
|
isFullScreen: jotai.PrimitiveAtom<boolean>;
|
2024-08-14 23:38:02 +02:00
|
|
|
controlShiftDelayAtom: jotai.PrimitiveAtom<boolean>;
|
2024-08-15 06:47:09 +02:00
|
|
|
reducedMotionPreferenceAtom: jotai.Atom<boolean>;
|
2024-08-06 20:05:26 +02:00
|
|
|
updaterStatusAtom: jotai.PrimitiveAtom<UpdaterStatus>;
|
2024-08-27 01:19:03 +02:00
|
|
|
typeAheadModalAtom: jotai.PrimitiveAtom<TypeAheadModalType>;
|
2024-08-30 01:06:15 +02:00
|
|
|
modalOpen: jotai.PrimitiveAtom<boolean>;
|
2024-07-19 22:44:32 +02:00
|
|
|
};
|
|
|
|
|
2024-08-15 03:40:41 +02:00
|
|
|
type WritableWaveObjectAtom<T extends WaveObj> = jotai.WritableAtom<T, [value: T], void>;
|
|
|
|
|
|
|
|
type ThrottledValueAtom<T> = jotai.WritableAtom<T, [update: jotai.SetStateAction<T>], void>;
|
|
|
|
|
|
|
|
type AtomWithThrottle<T> = {
|
|
|
|
currentValueAtom: jotai.Atom<T>;
|
|
|
|
throttledValueAtom: ThrottledValueAtom<T>;
|
|
|
|
};
|
|
|
|
|
|
|
|
type DebouncedValueAtom<T> = jotai.WritableAtom<T, [update: jotai.SetStateAction<T>], void>;
|
|
|
|
|
|
|
|
type AtomWithDebounce<T> = {
|
|
|
|
currentValueAtom: jotai.Atom<T>;
|
|
|
|
debouncedValueAtom: DebouncedValueAtom<T>;
|
|
|
|
};
|
|
|
|
|
|
|
|
type SplitAtom<Item> = Atom<Atom<Item>[]>;
|
|
|
|
type WritableSplitAtom<Item> = WritableAtom<PrimitiveAtom<Item>[], [SplitAtomAction<Item>], void>;
|
|
|
|
|
2024-06-04 22:05:44 +02:00
|
|
|
type TabLayoutData = {
|
|
|
|
blockId: string;
|
|
|
|
};
|
2024-06-14 01:49:25 +02:00
|
|
|
|
|
|
|
type ElectronApi = {
|
2024-08-22 00:04:39 +02:00
|
|
|
getAuthKey(): string;
|
2024-08-01 22:46:06 +02:00
|
|
|
getIsDev(): boolean;
|
2024-06-19 20:15:14 +02:00
|
|
|
getCursorPoint: () => Electron.Point;
|
2024-06-21 21:32:38 +02:00
|
|
|
getPlatform: () => NodeJS.Platform;
|
2024-07-18 03:42:49 +02:00
|
|
|
getEnv: (varName: string) => string;
|
2024-08-28 03:49:49 +02:00
|
|
|
getUserName: () => string;
|
2024-08-17 01:18:42 +02:00
|
|
|
showContextMenu: (menu?: ElectronContextMenuItem[]) => void;
|
2024-06-20 00:42:19 +02:00
|
|
|
onContextMenuClick: (callback: (id: string) => void) => void;
|
2024-06-26 18:39:41 +02:00
|
|
|
onNavigate: (callback: (url: string) => void) => void;
|
|
|
|
onIframeNavigate: (callback: (url: string) => void) => void;
|
2024-06-26 21:14:59 +02:00
|
|
|
downloadFile: (path: string) => void;
|
2024-06-28 03:09:30 +02:00
|
|
|
openExternal: (url: string) => void;
|
2024-07-22 22:33:10 +02:00
|
|
|
onFullScreenChange: (callback: (isFullScreen: boolean) => void) => void;
|
2024-08-06 20:05:26 +02:00
|
|
|
onUpdaterStatusChange: (callback: (status: UpdaterStatus) => void) => void;
|
|
|
|
getUpdaterStatus: () => UpdaterStatus;
|
|
|
|
installAppUpdate: () => void;
|
2024-08-20 00:49:40 +02:00
|
|
|
onMenuItemAbout: (callback: () => void) => void;
|
2024-08-19 23:16:09 +02:00
|
|
|
updateWindowControlsOverlay: (rect: Dimensions) => void;
|
2024-08-30 01:06:15 +02:00
|
|
|
onReinjectKey: (callback: (waveEvent: WaveKeyboardEvent) => void) => void;
|
|
|
|
setWebviewFocus: (focusedId: number) => void; // focusedId si the getWebContentsId of the webview
|
|
|
|
registerGlobalWebviewKeys: (keys: string[]) => void;
|
|
|
|
onControlShiftStateUpdate: (callback: (state: boolean) => void) => void;
|
2024-06-20 00:42:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
type ElectronContextMenuItem = {
|
|
|
|
id: string; // unique id, used for communication
|
|
|
|
label: string;
|
|
|
|
role?: string; // electron role (optional)
|
|
|
|
type?: "separator" | "normal" | "submenu";
|
|
|
|
submenu?: ElectronContextMenuItem[];
|
|
|
|
};
|
|
|
|
|
|
|
|
type ContextMenuItem = {
|
|
|
|
label?: string;
|
|
|
|
type?: "separator" | "normal" | "submenu";
|
|
|
|
role?: string; // electron role (optional)
|
|
|
|
click?: () => void; // not required if role is set
|
|
|
|
submenu?: ContextMenuItem[];
|
2024-06-14 01:49:25 +02:00
|
|
|
};
|
2024-06-18 07:38:48 +02:00
|
|
|
|
2024-06-21 21:32:38 +02:00
|
|
|
type KeyPressDecl = {
|
|
|
|
mods: {
|
|
|
|
Cmd?: boolean;
|
|
|
|
Option?: boolean;
|
|
|
|
Shift?: boolean;
|
|
|
|
Ctrl?: boolean;
|
|
|
|
Alt?: boolean;
|
|
|
|
Meta?: boolean;
|
|
|
|
};
|
|
|
|
key: string;
|
|
|
|
keyType: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
interface WaveKeyboardEvent {
|
2024-08-30 01:06:15 +02:00
|
|
|
type: "keydown" | "keyup" | "keypress" | "unknown";
|
2024-06-21 21:32:38 +02:00
|
|
|
/**
|
|
|
|
* Equivalent to KeyboardEvent.key.
|
|
|
|
*/
|
|
|
|
key: string;
|
|
|
|
/**
|
|
|
|
* Equivalent to KeyboardEvent.code.
|
|
|
|
*/
|
|
|
|
code: string;
|
|
|
|
/**
|
|
|
|
* Equivalent to KeyboardEvent.shiftKey.
|
|
|
|
*/
|
|
|
|
shift: boolean;
|
|
|
|
/**
|
|
|
|
* Equivalent to KeyboardEvent.controlKey.
|
|
|
|
*/
|
|
|
|
control: boolean;
|
|
|
|
/**
|
|
|
|
* Equivalent to KeyboardEvent.altKey.
|
|
|
|
*/
|
|
|
|
alt: boolean;
|
|
|
|
/**
|
|
|
|
* Equivalent to KeyboardEvent.metaKey.
|
|
|
|
*/
|
|
|
|
meta: boolean;
|
|
|
|
/**
|
|
|
|
* cmd is special, on mac it is meta, on windows it is alt
|
|
|
|
*/
|
|
|
|
cmd: boolean;
|
|
|
|
/**
|
|
|
|
* option is special, on mac it is alt, on windows it is meta
|
|
|
|
*/
|
|
|
|
option: boolean;
|
|
|
|
|
|
|
|
repeat: boolean;
|
|
|
|
/**
|
|
|
|
* Equivalent to KeyboardEvent.location.
|
|
|
|
*/
|
|
|
|
location: number;
|
|
|
|
}
|
|
|
|
|
2024-06-18 07:38:48 +02:00
|
|
|
type SubjectWithRef<T> = rxjs.Subject<T> & { refCount: number; release: () => void };
|
2024-07-09 00:04:48 +02:00
|
|
|
|
2024-08-24 03:12:40 +02:00
|
|
|
type HeaderElem = HeaderIconButton | HeaderText | HeaderInput | HeaderDiv | HeaderTextButton | ConnectionButton;
|
2024-07-09 08:13:12 +02:00
|
|
|
|
|
|
|
type HeaderIconButton = {
|
|
|
|
elemtype: "iconbutton";
|
2024-08-06 01:13:26 +02:00
|
|
|
icon: string | React.ReactNode;
|
2024-07-15 18:40:28 +02:00
|
|
|
className?: string;
|
2024-07-09 01:36:30 +02:00
|
|
|
title?: string;
|
2024-07-09 08:13:12 +02:00
|
|
|
click?: (e: React.MouseEvent<any>) => void;
|
|
|
|
longClick?: (e: React.MouseEvent<any>) => void;
|
2024-09-03 20:24:45 +02:00
|
|
|
disabled?: boolean;
|
2024-07-09 01:36:30 +02:00
|
|
|
};
|
|
|
|
|
2024-07-18 08:41:33 +02:00
|
|
|
type HeaderTextButton = {
|
|
|
|
elemtype: "textbutton";
|
|
|
|
text: string;
|
|
|
|
className?: string;
|
|
|
|
onClick?: (e: React.MouseEvent<any>) => void;
|
|
|
|
};
|
|
|
|
|
2024-07-09 08:13:12 +02:00
|
|
|
type HeaderText = {
|
|
|
|
elemtype: "text";
|
|
|
|
text: string;
|
2024-08-29 08:47:45 +02:00
|
|
|
ref?: React.MutableRefObject<HTMLDivElement>;
|
2024-08-31 20:57:45 +02:00
|
|
|
className?: string;
|
|
|
|
onClick?: () => void;
|
2024-07-09 08:13:12 +02:00
|
|
|
};
|
2024-07-09 01:36:30 +02:00
|
|
|
|
2024-07-15 18:40:28 +02:00
|
|
|
type HeaderInput = {
|
|
|
|
elemtype: "input";
|
|
|
|
value: string;
|
|
|
|
className?: string;
|
2024-07-18 08:41:33 +02:00
|
|
|
isDisabled?: boolean;
|
2024-07-15 18:40:28 +02:00
|
|
|
ref?: React.MutableRefObject<HTMLInputElement>;
|
|
|
|
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
|
|
onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
|
|
onFocus?: (e: React.FocusEvent<HTMLInputElement>) => void;
|
|
|
|
onBlur?: (e: React.FocusEvent<HTMLInputElement>) => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
type HeaderDiv = {
|
|
|
|
elemtype: "div";
|
|
|
|
className?: string;
|
|
|
|
children: HeaderElem[];
|
|
|
|
onMouseOver?: (e: React.MouseEvent<any>) => void;
|
|
|
|
onMouseOut?: (e: React.MouseEvent<any>) => void;
|
2024-08-24 03:12:40 +02:00
|
|
|
onClick?: (e: React.MouseEvent<any>) => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
type ConnectionButton = {
|
|
|
|
elemtype: "connectionbutton";
|
|
|
|
icon: string;
|
|
|
|
text: string;
|
|
|
|
iconColor: string;
|
|
|
|
onClick?: (e: React.MouseEvent<any>) => void;
|
|
|
|
connected: boolean;
|
2024-07-15 18:40:28 +02:00
|
|
|
};
|
|
|
|
|
2024-07-09 08:13:12 +02:00
|
|
|
interface ViewModel {
|
2024-08-23 01:25:53 +02:00
|
|
|
viewType: string;
|
2024-07-09 08:13:12 +02:00
|
|
|
viewIcon?: jotai.Atom<string | HeaderIconButton>;
|
|
|
|
viewName?: jotai.Atom<string>;
|
|
|
|
viewText?: jotai.Atom<string | HeaderElem[]>;
|
|
|
|
preIconButton?: jotai.Atom<HeaderIconButton>;
|
|
|
|
endIconButtons?: jotai.Atom<HeaderIconButton[]>;
|
2024-07-31 04:52:50 +02:00
|
|
|
blockBg?: jotai.Atom<MetaType>;
|
2024-08-27 01:19:03 +02:00
|
|
|
manageConnection?: jotai.Atom<boolean>;
|
2024-07-09 00:04:48 +02:00
|
|
|
|
|
|
|
onBack?: () => void;
|
|
|
|
onForward?: () => void;
|
|
|
|
onSearchChange?: (text: string) => void;
|
|
|
|
onSearch?: (text: string) => void;
|
|
|
|
getSettingsMenuItems?: () => ContextMenuItem[];
|
2024-07-23 01:41:18 +02:00
|
|
|
giveFocus?: () => boolean;
|
2024-08-20 03:41:47 +02:00
|
|
|
keyDownHandler?: (e: WaveKeyboardEvent) => boolean;
|
2024-07-09 00:04:48 +02:00
|
|
|
}
|
|
|
|
|
2024-08-07 00:13:59 +02:00
|
|
|
type UpdaterStatus = "up-to-date" | "checking" | "downloading" | "ready" | "error" | "installing";
|
2024-08-06 20:05:26 +02:00
|
|
|
|
2024-07-09 00:04:48 +02:00
|
|
|
// jotai doesn't export this type :/
|
|
|
|
type Loadable<T> = { state: "loading" } | { state: "hasData"; data: T } | { state: "hasError"; error: unknown };
|
2024-08-19 23:16:09 +02:00
|
|
|
|
|
|
|
interface Dimensions {
|
|
|
|
width: number;
|
|
|
|
height: number;
|
|
|
|
left: number;
|
|
|
|
top: number;
|
|
|
|
}
|
2024-08-23 09:18:49 +02:00
|
|
|
|
|
|
|
type TypeAheadModalType = { [key: string]: boolean };
|
2024-05-27 08:05:11 +02:00
|
|
|
}
|
2024-05-14 08:45:41 +02:00
|
|
|
|
|
|
|
export {};
|