/** * @fileOverview This file contains the the react contexts used in the project. */ import * as React from 'react'; import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js' import { InteractiveDiagnostic, InteractiveTermGoal } from '@leanprover/infoview-api'; import { GameHint, InteractiveGoal, InteractiveGoals } from './rpc_api'; import { PreferencesState } from '../../state/preferences'; export const MonacoEditorContext = React.createContext( null as any) export type InfoStatus = 'updating' | 'error' | 'ready'; /** One step of the proof */ export type ProofStep = { /** The command in this step */ command : string /** List of goals *after* this command */ goals: InteractiveGoal[] // TODO: Add correct type /** Story relevant messages */ hints: GameHint[] // TODO: Add correct type /** Errors and warnings */ errors: InteractiveDiagnostic[] // TODO: Add correct type } /** The context storing the proof step-by-step for the command line mode */ export const ProofContext = React.createContext<{ /** The proof consists of multiple steps that are processed one after the other. * In particular multi-line terms like `match`-statements will not be supported. * * Note that the first step will always have `null` as command */ proof: ProofStep[], setProof: React.Dispatch>> }>({ proof: [], setProof: () => {} // TODO: implement me }) export interface ProofStateProps { // pos: DocumentPosition; status: InfoStatus; messages: InteractiveDiagnostic[]; goals?: InteractiveGoals; termGoal?: InteractiveTermGoal; error?: string; // userWidgets: UserWidgetInstance[]; // rpcSess: RpcSessionAtPos; // triggerUpdate: () => Promise; } export const ProofStateContext = React.createContext<{ proofState : ProofStateProps, setProofState: React.Dispatch> }>({ proofState : { status: 'updating', messages: [], goals: undefined, termGoal: undefined, error: undefined}, setProofState: () => {}, }) export interface IPreferencesContext extends PreferencesState{ setLayout: React.Dispatch>; setIsSavePreferences: React.Dispatch>; } export const PreferencesContext = React.createContext({ layout: "auto", isSavePreferences: false, setLayout: () => {}, setIsSavePreferences: () => {} }) export interface IMobileContext { mobile : boolean, setMobile: React.Dispatch>, } export const MobileContext = React.createContext({ mobile: false, setMobile: () => {}, }) export const WorldLevelIdContext = React.createContext<{ worldId : string, levelId: number }>({ worldId : null, levelId: 0, }) /** Context to keep highlight selected proof step and corresponding chat messages. */ export const SelectionContext = React.createContext<{ selectedStep : number, setSelectedStep: React.Dispatch> }>({ selectedStep : undefined, setSelectedStep: () => {} }) /** Context for deleted Hints that are visible just a bit after they've been deleted */ export const DeletedChatContext = React.createContext<{ deletedChat : GameHint[], setDeletedChat: React.Dispatch>> showHelp : Set, setShowHelp: React.Dispatch>> }>({ deletedChat: undefined, setDeletedChat: () => {}, showHelp: undefined, setShowHelp: () => {} }) export const InputModeContext = React.createContext<{ typewriterMode: boolean, setTypewriterMode: React.Dispatch>, typewriterInput: string, setTypewriterInput: React.Dispatch>, lockInputMode: boolean, setLockInputMode: React.Dispatch>, }>({ typewriterMode: true, setTypewriterMode: () => {}, typewriterInput: "", setTypewriterInput: () => {}, lockInputMode: false, setLockInputMode: () => {}, });