mirror of https://github.com/nocodb/nocodb
braks
2 years ago
3 changed files with 53 additions and 66 deletions
@ -1,20 +1,20 @@
|
||||
<script lang="ts" setup> |
||||
import { useExpandedFormDetached } from '#imports' |
||||
|
||||
const { isOpen, state, row, rowId, loadRow: shouldLoadRow, meta, useMetaFields, view, close } = useExpandedFormDetached() |
||||
const { states } = useExpandedFormDetached() |
||||
</script> |
||||
|
||||
<template> |
||||
<LazySmartsheetExpandedForm |
||||
v-if="!!row && !!meta" |
||||
v-model="isOpen" |
||||
:row="row" |
||||
:load-row="shouldLoadRow" |
||||
:meta="meta" |
||||
:row-id="rowId" |
||||
:state="state" |
||||
:use-meta-fields="useMetaFields" |
||||
:view="view" |
||||
@cancel="close" |
||||
/> |
||||
<template v-for="(state, i) of states" :key="`expanded-form-${i}`"> |
||||
<LazySmartsheetExpandedForm |
||||
v-model="state.isOpen" |
||||
:row="state.row" |
||||
:load-row="state.loadRow" |
||||
:meta="state.meta" |
||||
:row-id="state.rowId" |
||||
:state="state.state" |
||||
:use-meta-fields="state.useMetaFields" |
||||
:view="state.view" |
||||
/> |
||||
</template> |
||||
</template> |
||||
|
@ -1,58 +1,41 @@
|
||||
import type { TableType, ViewType } from 'nocodb-sdk' |
||||
import { reactive, toRefs, useInjectionState } from '#imports' |
||||
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 |
||||
'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(() => { |
||||
const state = reactive<UseExpandedFormDetachedProps>({ |
||||
isOpen: false, |
||||
state: null, |
||||
loadRow: false, |
||||
useMetaFields: false, |
||||
row: null, |
||||
meta: null as any, |
||||
}) |
||||
return ref<UseExpandedFormDetachedProps[]>([]) |
||||
}) |
||||
|
||||
const open = (props: UseExpandedFormDetachedProps) => { |
||||
state.state = props.state |
||||
state.loadRow = props.loadRow |
||||
state.useMetaFields = props.useMetaFields |
||||
state.rowId = props.rowId |
||||
state.row = props.row |
||||
state.loadRow = props.loadRow |
||||
state.meta = props.meta |
||||
state.isOpen = props.isOpen |
||||
|
||||
state.isOpen = true |
||||
} |
||||
export function useExpandedFormDetached() { |
||||
let states = use()! |
||||
|
||||
const close = () => { |
||||
state.isOpen = false |
||||
if (!states) { |
||||
states = setup() |
||||
} |
||||
|
||||
return { |
||||
...toRefs(state), |
||||
open, |
||||
close, |
||||
} |
||||
}) |
||||
const index = ref(-1) |
||||
|
||||
export function useExpandedFormDetached() { |
||||
const state = use() |
||||
const open = (props: UseExpandedFormDetachedProps) => { |
||||
states.value.push(props) |
||||
index.value = states.value.length - 1 |
||||
} |
||||
|
||||
if (!state) { |
||||
return setup() |
||||
const close = () => { |
||||
states.value.splice(index.value, 1) |
||||
} |
||||
|
||||
return state |
||||
return { states, open, close } |
||||
} |
||||
|
Loading…
Reference in new issue