|
|
|
import type { TableType, ViewType } from 'nocodb-sdk'
|
|
|
|
import { ref, useInjectionState } from '#imports'
|
|
|
|
import type { Row } from '~/lib'
|
|
|
|
|
|
|
|
interface UseExpandedFormDetachedProps {
|
|
|
|
'isOpen'?: boolean
|
|
|
|
'row': Row | null
|
|
|
|
'state'?: Record<string, any> | null
|
|
|
|
'meta': TableType
|
|
|
|
'loadRow'?: boolean
|
|
|
|
'useMetaFields'?: boolean
|
|
|
|
'rowId'?: string
|
|
|
|
'view'?: ViewType
|
|
|
|
'onCancel'?: Function
|
|
|
|
'onUpdate:modelValue'?: Function
|
|
|
|
}
|
|
|
|
|
|
|
|
const [setup, use] = useInjectionState(() => {
|
|
|
|
return ref<UseExpandedFormDetachedProps[]>([])
|
|
|
|
})
|
|
|
|
|
|
|
|
export function useExpandedFormDetached() {
|
|
|
|
let states = use()!
|
|
|
|
|
|
|
|
if (!states) {
|
|
|
|
states = setup()
|
|
|
|
}
|
|
|
|
|
|
|
|
const index = ref(-1)
|
|
|
|
|
|
|
|
const open = (props: UseExpandedFormDetachedProps) => {
|
|
|
|
states.value.push(props)
|
|
|
|
index.value = states.value.length - 1
|
|
|
|
}
|
|
|
|
|
|
|
|
const close = () => {
|
|
|
|
states.value.splice(index.value, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return { states, open, close }
|
|
|
|
}
|