* move editor data into a singleton Signed-off-by: Jess Frazelle <github@jessfraz.com> * debounce on update Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * make select on extrude work Signed-off-by: Jess Frazelle <github@jessfraz.com> * highlight range Signed-off-by: Jess Frazelle <github@jessfraz.com> * highlight range Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix errors Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * almost forgot the error pane Signed-off-by: Jess Frazelle <github@jessfraz.com> * loint Signed-off-by: Jess Frazelle <github@jessfraz.com> * call out to codemirror Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix tauri; Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * more efficient Signed-off-by: Jess Frazelle <github@jessfraz.com> * create the modals in the hook Signed-off-by: Jess Frazelle <github@jessfraz.com> * Revert "create the modals in the hook" This reverts commit bbeba85030763cf7235a09fa24247dbf120f2a64. * change todo Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { useMachine } from '@xstate/react'
|
|
import { editorManager } from 'lib/singletons'
|
|
import { commandBarMachine } from 'machines/commandBarMachine'
|
|
import { createContext, useEffect } from 'react'
|
|
import { EventFrom, StateFrom } from 'xstate'
|
|
|
|
type CommandsContextType = {
|
|
commandBarState: StateFrom<typeof commandBarMachine>
|
|
commandBarSend: (event: EventFrom<typeof commandBarMachine>) => void
|
|
}
|
|
|
|
export const CommandsContext = createContext<CommandsContextType>({
|
|
commandBarState: commandBarMachine.initialState,
|
|
commandBarSend: () => {},
|
|
})
|
|
|
|
export const CommandBarProvider = ({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode
|
|
}) => {
|
|
const [commandBarState, commandBarSend] = useMachine(commandBarMachine, {
|
|
devTools: true,
|
|
guards: {
|
|
'Command has no arguments': (context, _event) => {
|
|
return (
|
|
!context.selectedCommand?.args ||
|
|
Object.keys(context.selectedCommand?.args).length === 0
|
|
)
|
|
},
|
|
},
|
|
})
|
|
|
|
useEffect(() => {
|
|
editorManager.setCommandBarSend(commandBarSend)
|
|
})
|
|
|
|
return (
|
|
<CommandsContext.Provider
|
|
value={{
|
|
commandBarState,
|
|
commandBarSend,
|
|
}}
|
|
>
|
|
{children}
|
|
</CommandsContext.Provider>
|
|
)
|
|
}
|