mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
4.3 KiB
176 lines
4.3 KiB
3 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import { UITypes } from 'nocodb-sdk'
|
||
3 years ago
|
import type { ColumnType } from 'nocodb-sdk'
|
||
2 years ago
|
import {
|
||
|
ActiveCellInj,
|
||
|
ColumnInj,
|
||
|
EditModeInj,
|
||
|
IsFormInj,
|
||
|
IsLockedInj,
|
||
|
IsPublicInj,
|
||
|
computed,
|
||
2 years ago
|
inject,
|
||
2 years ago
|
provide,
|
||
2 years ago
|
ref,
|
||
2 years ago
|
toRef,
|
||
|
useColumn,
|
||
|
useDebounceFn,
|
||
|
useVModel,
|
||
|
} from '#imports'
|
||
2 years ago
|
import { NavigateDir } from '~/lib'
|
||
3 years ago
|
|
||
2 years ago
|
interface Props {
|
||
|
column: ColumnType
|
||
|
modelValue: any
|
||
2 years ago
|
editEnabled: boolean
|
||
2 years ago
|
readOnly?: boolean
|
||
2 years ago
|
rowIndex?: number
|
||
2 years ago
|
active?: boolean
|
||
2 years ago
|
virtual?: boolean
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
const props = defineProps<Props>()
|
||
2 years ago
|
|
||
2 years ago
|
const emit = defineEmits(['update:modelValue', 'save', 'navigate', 'update:editEnabled'])
|
||
2 years ago
|
|
||
2 years ago
|
const column = toRef(props, 'column')
|
||
2 years ago
|
|
||
2 years ago
|
const active = toRef(props, 'active', false)
|
||
|
|
||
2 years ago
|
const virtual = toRef(props, 'virtual', false)
|
||
|
|
||
2 years ago
|
const readOnly = toRef(props, 'readOnly', undefined)
|
||
|
|
||
2 years ago
|
provide(ColumnInj, column)
|
||
2 years ago
|
|
||
2 years ago
|
provide(EditModeInj, useVModel(props, 'editEnabled', emit))
|
||
2 years ago
|
|
||
2 years ago
|
provide(ActiveCellInj, active)
|
||
|
|
||
2 years ago
|
if (readOnly?.value) {
|
||
|
provide(ReadonlyInj, readOnly.value)
|
||
|
}
|
||
|
|
||
2 years ago
|
const isForm = inject(IsFormInj, ref(false))
|
||
2 years ago
|
|
||
2 years ago
|
const isPublic = inject(IsPublicInj, ref(false))
|
||
2 years ago
|
|
||
2 years ago
|
const isLocked = inject(IsLockedInj, ref(false))
|
||
2 years ago
|
|
||
2 years ago
|
let changed = $ref(false)
|
||
2 years ago
|
|
||
2 years ago
|
const syncValue = useDebounceFn(function () {
|
||
2 years ago
|
changed = false
|
||
2 years ago
|
emit('save')
|
||
|
}, 1000)
|
||
|
|
||
|
const isAutoSaved = $computed(() => {
|
||
|
return [
|
||
|
UITypes.SingleLineText,
|
||
|
UITypes.LongText,
|
||
|
UITypes.PhoneNumber,
|
||
|
UITypes.Email,
|
||
|
UITypes.URL,
|
||
|
UITypes.Number,
|
||
|
UITypes.Decimal,
|
||
|
UITypes.Percent,
|
||
|
UITypes.Count,
|
||
|
UITypes.AutoNumber,
|
||
|
UITypes.SpecificDBType,
|
||
|
UITypes.Geometry,
|
||
2 years ago
|
].includes(column?.value?.uidt as UITypes)
|
||
2 years ago
|
})
|
||
|
|
||
|
const isManualSaved = $computed(() => {
|
||
2 years ago
|
return [UITypes.Currency, UITypes.Duration].includes(column?.value?.uidt as UITypes)
|
||
2 years ago
|
})
|
||
|
|
||
|
const vModel = computed({
|
||
2 years ago
|
get: () => props.modelValue,
|
||
2 years ago
|
set: (val) => {
|
||
2 years ago
|
if (val !== props.modelValue) {
|
||
2 years ago
|
changed = true
|
||
|
emit('update:modelValue', val)
|
||
|
if (isAutoSaved) {
|
||
|
syncValue()
|
||
|
} else if (!isManualSaved) {
|
||
|
emit('save')
|
||
2 years ago
|
changed = true
|
||
2 years ago
|
}
|
||
|
}
|
||
|
},
|
||
|
})
|
||
3 years ago
|
|
||
|
const {
|
||
2 years ago
|
isPrimary,
|
||
3 years ago
|
isURL,
|
||
|
isEmail,
|
||
|
isJSON,
|
||
|
isDate,
|
||
2 years ago
|
isYear,
|
||
3 years ago
|
isDateTime,
|
||
|
isTime,
|
||
|
isBoolean,
|
||
|
isDuration,
|
||
|
isRating,
|
||
|
isCurrency,
|
||
|
isAttachment,
|
||
|
isTextArea,
|
||
2 years ago
|
isString,
|
||
2 years ago
|
isInt,
|
||
|
isFloat,
|
||
2 years ago
|
isDecimal,
|
||
2 years ago
|
isSingleSelect,
|
||
|
isMultiSelect,
|
||
2 years ago
|
isPercent,
|
||
2 years ago
|
isPhoneNumber,
|
||
2 years ago
|
} = useColumn(column)
|
||
2 years ago
|
|
||
|
const syncAndNavigate = (dir: NavigateDir) => {
|
||
2 years ago
|
if (isJSON.value) return
|
||
2 years ago
|
|
||
2 years ago
|
if (changed) {
|
||
|
emit('save')
|
||
|
changed = false
|
||
|
}
|
||
|
emit('navigate', dir)
|
||
|
}
|
||
3 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<div
|
||
2 years ago
|
class="nc-cell w-full h-full"
|
||
2 years ago
|
:class="{ 'text-blue-600': isPrimary && !virtual && !isForm }"
|
||
2 years ago
|
@keydown.stop.left
|
||
|
@keydown.stop.right
|
||
|
@keydown.stop.up
|
||
|
@keydown.stop.down
|
||
|
@keydown.stop.enter.exact="syncAndNavigate(NavigateDir.NEXT)"
|
||
|
@keydown.stop.shift.enter.exact="syncAndNavigate(NavigateDir.PREV)"
|
||
|
>
|
||
2 years ago
|
<CellTextArea v-if="isTextArea" v-model="vModel" />
|
||
|
<CellCheckbox v-else-if="isBoolean" v-model="vModel" />
|
||
2 years ago
|
<CellAttachment v-else-if="isAttachment" v-model="vModel" :row-index="props.rowIndex" />
|
||
2 years ago
|
<CellSingleSelect v-else-if="isSingleSelect" v-model="vModel" />
|
||
|
<CellMultiSelect v-else-if="isMultiSelect" v-model="vModel" />
|
||
|
<CellDatePicker v-else-if="isDate" v-model="vModel" />
|
||
|
<CellYearPicker v-else-if="isYear" v-model="vModel" />
|
||
|
<CellDateTimePicker v-else-if="isDateTime" v-model="vModel" />
|
||
|
<CellTimePicker v-else-if="isTime" v-model="vModel" />
|
||
|
<CellRating v-else-if="isRating" v-model="vModel" />
|
||
|
<CellDuration v-else-if="isDuration" v-model="vModel" />
|
||
|
<CellEmail v-else-if="isEmail" v-model="vModel" />
|
||
|
<CellUrl v-else-if="isURL" v-model="vModel" />
|
||
|
<CellPhoneNumber v-else-if="isPhoneNumber" v-model="vModel" />
|
||
2 years ago
|
<CellPercent v-else-if="isPercent" v-model="vModel" />
|
||
2 years ago
|
<CellCurrency v-else-if="isCurrency" v-model="vModel" />
|
||
|
<CellDecimal v-else-if="isDecimal" v-model="vModel" />
|
||
|
<CellInteger v-else-if="isInt" v-model="vModel" />
|
||
|
<CellFloat v-else-if="isFloat" v-model="vModel" />
|
||
|
<CellText v-else-if="isString" v-model="vModel" />
|
||
2 years ago
|
<CellJson v-else-if="isJSON" v-model="vModel" />
|
||
2 years ago
|
<CellText v-else v-model="vModel" />
|
||
2 years ago
|
<div v-if="(isLocked || (isPublic && readOnly && !isForm)) && !isAttachment" class="nc-locked-overlay" @click.stop.prevent />
|
||
2 years ago
|
</div>
|
||
3 years ago
|
</template>
|