-
-
Notifications
You must be signed in to change notification settings - Fork 953
Expand file tree
/
Copy pathwaveenv.ts
More file actions
40 lines (33 loc) · 1.42 KB
/
waveenv.ts
File metadata and controls
40 lines (33 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
import { RpcApiType } from "@/app/store/wshclientapi";
import { Atom, PrimitiveAtom } from "jotai";
import React from "react";
type ConfigAtoms = { [K in keyof SettingsType]: Atom<SettingsType[K]> };
export type BlockMetaKeyAtomFnType<Keys extends keyof MetaType = keyof MetaType> = <T extends Keys>(
blockId: string,
key: T
) => Atom<MetaType[T]>;
// default implementation for production is in ./waveenvimpl.ts
export type WaveEnv = {
electron: ElectronApi;
rpc: RpcApiType;
platform: NodeJS.Platform;
configAtoms: ConfigAtoms;
isDev: () => boolean;
isWindows: () => boolean;
isMacOS: () => boolean;
atoms: GlobalAtomsType;
createBlock: (blockDef: BlockDef, magnified?: boolean, ephemeral?: boolean) => Promise<string>;
showContextMenu: (menu: ContextMenuItem[], e: React.MouseEvent) => void;
getConnStatusAtom: (conn: string) => PrimitiveAtom<ConnStatus>;
getWaveObjectAtom: <T extends WaveObj>(oref: string) => Atom<T>;
getBlockMetaKeyAtom: BlockMetaKeyAtomFnType;
};
export const WaveEnvContext = React.createContext<WaveEnv>(null);
type EnvContract<T> = {
[K in keyof T]?: T[K] extends (...args: any[]) => any ? T[K] : T[K] extends object ? EnvContract<T[K]> : T[K];
};
export function useWaveEnv<T extends EnvContract<WaveEnv> = WaveEnv>(): T {
return React.useContext(WaveEnvContext) as T;
}