-
-
Notifications
You must be signed in to change notification settings - Fork 929
Expand file tree
/
Copy pathwaveenv.ts
More file actions
29 lines (23 loc) · 1003 Bytes
/
waveenv.ts
File metadata and controls
29 lines (23 loc) · 1003 Bytes
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
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
import { RpcApiType } from "@/app/store/wshclientapi";
import { Atom } from "jotai";
import React from "react";
type ConfigAtoms = { [K in keyof SettingsType]: Atom<SettingsType[K]> };
// default implementation for production is in ./waveenvimpl.ts
export type WaveEnv = {
electron: ElectronApi;
rpc: RpcApiType;
configAtoms: ConfigAtoms;
isDev: () => boolean;
atoms: GlobalAtomsType;
createBlock: (blockDef: BlockDef, magnified?: boolean, ephemeral?: boolean) => Promise<string>;
showContextMenu: (menu: ContextMenuItem[], e: React.MouseEvent) => void;
};
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;
}