mirror of https://github.com/nocodb/nocodb
DarkPhoenix2704
1 year ago
24 changed files with 254 additions and 105 deletions
@ -1,21 +1,81 @@ |
|||||||
<script setup lang="ts"> |
<script lang="ts" setup> |
||||||
import { useVModel } from '#imports' |
import type { VNodeRef } from '@vue/runtime-core' |
||||||
|
import { EditModeInj, IsExpandedFormOpenInj, IsSurveyFormInj, computed, inject, validatePhone } from '#imports' |
||||||
|
|
||||||
interface Props { |
interface Props { |
||||||
modelValue: any |
modelValue: string | null | number | undefined |
||||||
|
isFocus?: boolean |
||||||
} |
} |
||||||
|
|
||||||
interface Emits { |
const { modelValue: value, isFocus } = defineProps<Props>() |
||||||
(event: 'update:modelValue', model: string): void |
|
||||||
|
const emit = defineEmits(['update:modelValue']) |
||||||
|
|
||||||
|
const rowHeight = inject(RowHeightInj, ref(undefined)) |
||||||
|
|
||||||
|
const { showNull } = useGlobal() |
||||||
|
|
||||||
|
const editEnabled = inject(EditModeInj)! |
||||||
|
|
||||||
|
const column = inject(ColumnInj)! |
||||||
|
|
||||||
|
// Used in the logic of when to display error since we are not storing the phone if it's not valid |
||||||
|
const localState = ref(value) |
||||||
|
|
||||||
|
const isSurveyForm = inject(IsSurveyFormInj, ref(false)) |
||||||
|
|
||||||
|
const vModel = computed({ |
||||||
|
get: () => value, |
||||||
|
set: (val) => { |
||||||
|
localState.value = val |
||||||
|
if (!parseProp(column.value.meta)?.validate || (val && validatePhone(val)) || !val || isSurveyForm.value) { |
||||||
|
emit('update:modelValue', val) |
||||||
} |
} |
||||||
|
}, |
||||||
|
}) |
||||||
|
|
||||||
|
const validEmail = computed(() => vModel.value && validatePhone(vModel.value)) |
||||||
|
|
||||||
const props = defineProps<Props>() |
const isExpandedFormOpen = inject(IsExpandedFormOpenInj, ref(false))! |
||||||
|
|
||||||
const emits = defineEmits<Emits>() |
const focus: VNodeRef = (el) => !isExpandedFormOpen.value && isFocus && (el as HTMLInputElement)?.focus() |
||||||
|
|
||||||
const vModel = useVModel(props, 'modelValue', emits) |
watch( |
||||||
|
() => editEnabled.value, |
||||||
|
() => { |
||||||
|
if (parseProp(column.value.meta)?.validate && !editEnabled.value && localState.value && !validatePhone(localState.value)) { |
||||||
|
message.error('Invalid Phone Number') |
||||||
|
localState.value = undefined |
||||||
|
return |
||||||
|
} |
||||||
|
localState.value = value |
||||||
|
}, |
||||||
|
) |
||||||
</script> |
</script> |
||||||
|
|
||||||
<template> |
<template> |
||||||
<LazyCellText v-model="vModel" /> |
<input |
||||||
|
v-if="editEnabled" |
||||||
|
:ref="focus" |
||||||
|
v-model="vModel" |
||||||
|
class="w-full outline-none text-sm py-2" |
||||||
|
@blur="editEnabled = false" |
||||||
|
@keydown.down.stop |
||||||
|
@keydown.left.stop |
||||||
|
@keydown.right.stop |
||||||
|
@keydown.up.stop |
||||||
|
@keydown.delete.stop |
||||||
|
@keydown.ctrl.z.stop |
||||||
|
@keydown.meta.z.stop |
||||||
|
@selectstart.capture.stop |
||||||
|
@mousedown.stop |
||||||
|
/> |
||||||
|
|
||||||
|
<span v-else-if="vModel === null && showNull" class="nc-null">NULL</span> |
||||||
|
|
||||||
|
<a v-else-if="validEmail" class="text-sm underline hover:opacity-75" :href="`tel:${vModel}`" target="_blank"> |
||||||
|
<LazyCellClampedText :value="vModel" :lines="rowHeight" /> |
||||||
|
</a> |
||||||
|
|
||||||
|
<LazyCellClampedText v-else :value="vModel" :lines="rowHeight" /> |
||||||
</template> |
</template> |
||||||
|
@ -0,0 +1,31 @@ |
|||||||
|
<script lang="ts" setup> |
||||||
|
const props = defineProps<{ |
||||||
|
value: any |
||||||
|
}>() |
||||||
|
const emit = defineEmits(['update:value']) |
||||||
|
|
||||||
|
const column = inject(ColumnInj) |
||||||
|
|
||||||
|
provide('isAdvancedOption', ref(true)) |
||||||
|
|
||||||
|
const rowRef = ref({ |
||||||
|
row: {}, |
||||||
|
oldRow: {}, |
||||||
|
rowMeta: { |
||||||
|
isUpdatedFromCopyNPaste: [column?.value.title], |
||||||
|
}, |
||||||
|
}) |
||||||
|
|
||||||
|
const vModel = useVModel(props, 'value', emit) |
||||||
|
|
||||||
|
useProvideSmartsheetRowStore(vModel, rowRef) |
||||||
|
</script> |
||||||
|
|
||||||
|
<template> |
||||||
|
<p class="mt-3 text-[0.75rem]">Default Value</p> |
||||||
|
<div class="border-1 px-1 my-[-4px] border-gray-300 rounded-md"> |
||||||
|
<LazySmartsheetCell :column="vModel" :model-value="vModel.cdf" :edit-enabled="true" /> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
|
||||||
|
<style scoped></style> |
Loading…
Reference in new issue