Browse Source

fix(gui-v2): use cellRef for dropzone and teleport

pull/3066/head
braks 2 years ago
parent
commit
727b3c59a7
  1. 24
      packages/nc-gui-v2/components/cell/attachment/index.vue
  2. 6
      packages/nc-gui-v2/components/smartsheet/Grid.vue

24
packages/nc-gui-v2/components/cell/attachment/index.vue

@ -1,10 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { onKeyDown } from '@vueuse/core' import { onKeyDown } from '@vueuse/core'
import { useProvideAttachmentCell } from './utils' import { useProvideAttachmentCell } from './utils'
import Modal from './Modal.vue'
import { useSortable } from './sort' import { useSortable } from './sort'
import Modal from './Modal.vue'
import Carousel from './Carousel.vue' import Carousel from './Carousel.vue'
import { onMounted, ref, useDropZone, watch } from '#imports' import { computed, ref, useDropZone, useSmartsheetStoreOrThrow, watch } from '#imports'
import { isImage, openLink } from '~/utils' import { isImage, openLink } from '~/utils'
interface Props { interface Props {
@ -20,16 +20,18 @@ const { modelValue, rowIndex } = defineProps<Props>()
const emits = defineEmits<Emits>() const emits = defineEmits<Emits>()
const dropZoneRef = ref<HTMLTableDataCellElement>()
const sortableRef = ref<HTMLDivElement>() const sortableRef = ref<HTMLDivElement>()
const { cellRefs } = useSmartsheetStoreOrThrow()!
const { column, modalVisible, attachments, visibleItems, onDrop, isLoading, open, FileIcon, selectedImage, isReadonly } = const { column, modalVisible, attachments, visibleItems, onDrop, isLoading, open, FileIcon, selectedImage, isReadonly } =
useProvideAttachmentCell(updateModelValue) useProvideAttachmentCell(updateModelValue)
const currentCellRef = computed(() => cellRefs.value.find((cell) => cell.dataset.key === `${rowIndex}${column.value.id}`))
const { dragging } = useSortable(sortableRef, visibleItems, updateModelValue, isReadonly) const { dragging } = useSortable(sortableRef, visibleItems, updateModelValue, isReadonly)
const { isOverDropZone } = useDropZone(dropZoneRef, onDrop) const { isOverDropZone } = useDropZone(currentCellRef, onDrop)
/** on new value, reparse our stored attachments */ /** on new value, reparse our stored attachments */
watch( watch(
@ -52,25 +54,17 @@ onKeyDown('Escape', () => {
modalVisible.value = false modalVisible.value = false
isOverDropZone.value = false isOverDropZone.value = false
}) })
/** if possible, on mounted we try to fetch the relevant `td` cell to use as a dropzone */
onMounted(() => {
if (typeof document !== 'undefined') {
dropZoneRef.value = document.querySelector(`td[data-key="${rowIndex}${column.value.id}"]`) as HTMLTableDataCellElement
console.log(dropZoneRef.value)
}
})
</script> </script>
<template> <template>
<div class="nc-attachment-cell relative flex-1 color-transition flex items-center justify-between gap-1"> <div class="nc-attachment-cell relative flex-1 color-transition flex items-center justify-between gap-1">
<Carousel /> <Carousel />
<template v-if="!isReadonly && !dragging && dropZoneRef"> <template v-if="!isReadonly && !dragging && !!currentCellRef">
<general-overlay <general-overlay
v-model="isOverDropZone" v-model="isOverDropZone"
inline inline
:target="`td[data-key='${rowIndex}${column.id}']`" :target="currentCellRef"
class="text-white text-lg ring ring-pink-500 bg-gray-700/75 flex items-center justify-center gap-2 backdrop-blur-xl" class="text-white text-lg ring ring-pink-500 bg-gray-700/75 flex items-center justify-center gap-2 backdrop-blur-xl"
> >
<MaterialSymbolsFileCopyOutline class="text-pink-500" /> Drop here <MaterialSymbolsFileCopyOutline class="text-pink-500" /> Drop here

6
packages/nc-gui-v2/components/smartsheet/Grid.vue

@ -1,18 +1,18 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onClickOutside, useEventListener } from '@vueuse/core'
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import { UITypes, isVirtualCol } from 'nocodb-sdk' import { UITypes, isVirtualCol } from 'nocodb-sdk'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import { import {
inject, inject,
onClickOutside,
onMounted, onMounted,
provide, provide,
reactive, reactive,
ref, ref,
useEventListener,
useGridViewColumnWidth, useGridViewColumnWidth,
useProvideColumnCreateStore, useProvideColumnCreateStore,
useSmartsheetStoreOrThrow, useSmartsheetStoreOrThrow,
useTemplateRefsList,
useViewData, useViewData,
watch, watch,
} from '#imports' } from '#imports'
@ -341,7 +341,7 @@ const onNavigate = (dir: NavigateDir) => {
<td <td
v-for="(columnObj, colIndex) of fields" v-for="(columnObj, colIndex) of fields"
:ref="cellRefs.set" :ref="cellRefs.set"
:key="rowIndex + columnObj.title" :key="columnObj.id"
class="cell relative cursor-pointer nc-grid-cell" class="cell relative cursor-pointer nc-grid-cell"
:class="{ :class="{
active: !isPublicView && selected.col === colIndex && selected.row === rowIndex, active: !isPublicView && selected.col === colIndex && selected.row === rowIndex,

Loading…
Cancel
Save