From d829c6a10e6265eff26d2b6ea527b11e26ca27e0 Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Thu, 23 Nov 2023 11:20:38 +0000 Subject: [PATCH] fix: Added drag and drop support for rich modal --- packages/nc-gui/components/cell/TextArea.vue | 96 ++++++++++++++++++-- 1 file changed, 87 insertions(+), 9 deletions(-) diff --git a/packages/nc-gui/components/cell/TextArea.vue b/packages/nc-gui/components/cell/TextArea.vue index 04a0f8a489..f6016046bb 100644 --- a/packages/nc-gui/components/cell/TextArea.vue +++ b/packages/nc-gui/components/cell/TextArea.vue @@ -37,6 +37,19 @@ const vModel = useVModel(props, 'modelValue', emits, { defaultValue: column?.val const isExpandedFormOpen = inject(IsExpandedFormOpenInj, ref(false))! +const position = ref< + | { + top: number + left: number + } + | undefined +>({ + top: 200, + left: 600, +}) + +const isDragging = ref(false) + const focus: VNodeRef = (el) => !isExpandedFormOpen.value && !isEditColumn.value && (el as HTMLTextAreaElement)?.focus() const height = computed(() => { @@ -46,6 +59,7 @@ const height = computed(() => { }) const isVisible = ref(false) + const inputWrapperRef = ref(null) const inputRef = ref(null) @@ -84,10 +98,72 @@ const isRichMode = computed(() => { return meta?.richMode }) + +const onExpand = () => { + isVisible.value = true + + const { top, left } = inputWrapperRef.value?.getBoundingClientRect() ?? { top: 0, left: 0 } + + position.value = { + top: top + 42, + left, + } +} + +const onMouseMove = (e: MouseEvent) => { + if (!isDragging.value) return + + e.stopPropagation() + + position.value = { + top: e.clientY - 22, + left: e.clientX - 46, + } +} + +const onMouseUp = (e: MouseEvent) => { + if (!isDragging.value) return + + e.stopPropagation() + + isDragging.value = false + position.value = undefined + + document.removeEventListener('mousemove', onMouseMove) + document.removeEventListener('mouseup', onMouseUp) +} + +watch(position, () => { + const dom = document.querySelector('.nc-textarea-dropdown-active') as HTMLElement + if (!dom) return + + if (!position.value) return + + // Set left and top of dom + setTimeout(() => { + if (!position.value) return + + dom.style.left = `${position.value.left}px` + dom.style.top = `${position.value.top}px` + }, 100) +}) + +const dragStart = () => { + document.addEventListener('mousemove', onMouseMove) + document.addEventListener('mouseup', onMouseUp) + + isDragging.value = true +}