import { createContext, type JSX, useContext } from "solid-js" export type PlatformFiles = Readonly<{ readText(path: string): Promise readBytes(path: string): Promise mime(path: string): Promise }> export type PlatformClipboardContent = Readonly<{ data: string mime: string }> export type TuiPlatform = Readonly<{ files: PlatformFiles state?: Readonly<{ read(): Promise> write(value: Record): Promise }> themes?: Readonly<{ discover(): Promise> subscribeRefresh?(refresh: () => void): () => void }> clipboard?: Readonly<{ read?(): Promise write?(text: string): Promise }> editor?: Readonly<{ open(input: Readonly<{ value: string; cwd?: string }>): Promise connection?(directory: string): Readonly<{ url: string; authToken?: string; source: string }> | undefined selection?(directory: string): Promise }> export?: Readonly<{ write(path: string, content: string): Promise }> }> const PlatformContext = createContext() export function TuiPlatformProvider(props: { value: TuiPlatform; children: JSX.Element }) { return {props.children} } export function useTuiPlatform() { const value = useContext(PlatformContext) if (!value) throw new Error("TuiPlatformProvider is missing") return value } export function useOptionalTuiPlatform() { return useContext(PlatformContext) }