import { inject , computed , Ref } from 'vue' ; import { ComponentsContext } from './Context' ; import { Theme , ThemeLayoutsNames , FormDefine , HeaderDefine , } from './ThemeProvider' ; import { BuiltInWidgets , WidgetComponentDefine , getWidget } from './utils' ; import { Schema } from '../types' ; import { SingleTypeArrayDefine } from './types' ; export function useThemeContext ( ) { const context = inject ( ComponentsContext ) ; if ( ! context || ! context . value ) { throw new Error ( 'Theme needed' ) ; } return context ; } /**
 * override function can not fix problem
 * we may pass `name` in condition type
 * override will emit error when we doing that
 */ export function useComponent < N extends ThemeLayoutsNames > ( name ) { const context = useThemeContext ( ) ; const Component = computed ( ( ) => context . value . layouts [ name ] ) ; return Component as any ; } export function useWidget ( schema , widget ) { const context = useThemeContext ( ) ; const Component = computed ( ( ) => { const Widget = getWidget ( schema , widget , context . value . widgets ) ; return Widget ; } ) ; return Component ; }