π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat: canvas table cell drop
Ramesh Mane03162ecd2c82
diff --git a/packages/nc-gui/components/cell/attachment/index.vue b/packages/nc-gui/components/cell/attachment/index.vueindex 93a1e83950..e574de7738 100644--- a/packages/nc-gui/components/cell/attachment/index.vue+++ b/packages/nc-gui/components/cell/attachment/index.vue@@ -297,6 +297,10 @@ onMounted(() => {forcedNextTick(() => {if (onCellEvent(canvasCellEventData.event)) return+ if (canvasCellEventData.event && canvasCellEventData.files) {+ return onDrop(canvasCellEventData.files, canvasCellEventData.event)+ }+const clickableSelectors = ['.view-attachments', '.add-files', '.nc-attachment', '.empty-add-files'].map((selector) => `.nc-canvas-table-editable-cell-wrapper ${selector}`).join(', ')diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts b/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.tsindex 2d1a1a6a4d..0f5e73c8bd 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts+++ b/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts@@ -58,6 +58,7 @@ export function useGridCellHandler(params: {meta?: Ref<TableType>hasEditPermission: ComputedRef<boolean>setCursor: SetCursorType+ attachmentCellDropOver: Ref<AttachmentCellDropOverType | null>}) {const isPublic = inject(IsPublicInj, ref(false))@@ -278,7 +279,7 @@ export function useGridCellHandler(params: {}if (cellRenderer!) {- return cellRenderer(ctx, {+ const cellRendered = cellRenderer(ctx, {value,row,column,@@ -324,6 +325,34 @@ export function useGridCellHandler(params: {rowMeta,allowLocalUrl: appInfo.value?.allowLocalUrl,})++ if (+ !isGroupHeader &&+ isRootCell &&+ column.uidt === UITypes.Attachment &&+ !column.readonly &&+ params.attachmentCellDropOver.value?.columnId === column.id &&+ params.attachmentCellDropOver.value?.rowIndex === rowMeta.rowIndex+ ) {+ roundedRect(ctx, x, y, width, height, 0, {+ backgroundColor: themeV3Colors.gray['200'],+ borderColor: themeV3Colors.gray['200'],+ borderWidth: 0.4,+ })++ renderSingleLineText(ctx, {+ x: x + width / 2 - 10,+ y,+ textAlign: 'center',+ text: 'Drap Here',+ maxWidth: width - 10 * 2,+ fontFamily: `${pv ? 600 : 500} 13px Inter`,+ fillStyle: '#3366FF',+ height,+ })+ }++ return cellRendered} else {return renderSingleLineText(ctx, {x: x + padding,@@ -445,6 +474,17 @@ export function useGridCellHandler(params: {}}+ const handleCellDrop = async (ctx: { e: DragEvent; row: Row; column: CanvasGridColumn; files: File[] | null }) => {+ if (ctx.column?.readonly) return++ canvasCellEvents.files = ctx.files+ canvasCellEvents.event = ctx.e++ makeCellEditable(ctx.row, ctx.column, true)++ return true+ }+let cleanUpInterval: ReturnType<typeof setInterval> | null = nullonMounted(() => {@@ -471,5 +511,6 @@ export function useGridCellHandler(params: {handleCellClick,handleCellKeyDown,handleCellHover,+ handleCellDrop,}}diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.tsindex 49bb155444..f5b6b996e8 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts+++ b/packages/nc-gui/components/smartsheet/grid/canvas/composables/useCanvasTable.ts@@ -189,6 +189,7 @@ export function useCanvasTable({const editEnabled = ref<CanvasEditEnabledType>(null)const isFillMode = ref(false)const dragOver = ref<{ id: string; index: number } | null>(null)+ const attachmentCellDropOver = ref<AttachmentCellDropOverType | null>(null)const spriteLoader = new SpriteLoader(() => triggerRefreshCanvas())const imageLoader = new ImageWindowLoader(() => triggerRefreshCanvas())const tableMetaLoader = new TableMetaLoader(getMeta, () => triggerRefreshCanvas)@@ -791,7 +792,7 @@ export function useCanvasTable({}}- const { handleCellClick, renderCell, handleCellHover, handleCellKeyDown } = useGridCellHandler({+ const { handleCellClick, renderCell, handleCellHover, handleCellKeyDown, handleCellDrop } = useGridCellHandler({getCellPosition,actionManager,updateOrSaveRow,@@ -799,6 +800,7 @@ export function useCanvasTable({meta,hasEditPermission: isDataEditAllowed,setCursor,+ attachmentCellDropOver,})const { canvasRef, renderCanvas, colResizeHoveredColIds } = useCanvasRender({@@ -1373,6 +1375,7 @@ export function useCanvasTable({partialRowHeight,readOnly,dragOver,+ attachmentCellDropOver,// columnresize related refscolResizeHoveredColIds,@@ -1448,6 +1451,7 @@ export function useCanvasTable({baseRoleLoader,handleCellClick,handleCellHover,+ handleCellDrop,renderCell,totalColumnsWidth,diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/index.vue b/packages/nc-gui/components/smartsheet/grid/canvas/index.vueindex 99ed62b271..af5267ad7c 100644--- a/packages/nc-gui/components/smartsheet/grid/canvas/index.vue+++ b/packages/nc-gui/components/smartsheet/grid/canvas/index.vue@@ -294,6 +294,7 @@ const {findColumnPosition,findColumnAtPosition,dragOver,+ attachmentCellDropOver,dragStart,elementMap,// MouseSelectionHandler@@ -339,6 +340,9 @@ const {// Cell HoverhandleCellHover,+ // Cell Drop+ handleCellDrop,+actionManager,imageLoader,readOnly,@@ -2612,6 +2616,107 @@ useActiveKeydownListener(},)+const resetAttachmentCellDropOver = () => {+ if (!attachmentCellDropOver.value || attachmentCellDropOver.value.rowIndex === -1) return++ attachmentCellDropOver.value = {+ rowIndex: -1,+ columnId: '',+ path: [],+ uploadingCells: attachmentCellDropOver.value?.uploadingCells ?? [],+ }++ requestAnimationFrame(triggerRefreshCanvas)+}++const onDrop = (files: File[] | null, event: DragEvent) => {+ if (!attachmentCellDropOver.value || attachmentCellDropOver.value.rowIndex === -1) return++ const dataCache = getDataCache(attachmentCellDropOver.value.path)++ const row =+ attachmentCellDropOver.value.rowIndex !== null+ ? dataCache.cachedRows.value.get(attachmentCellDropOver.value.rowIndex!)+ : undefined++ const columnIndex = columns.value.findIndex((col) => col.id === attachmentCellDropOver.value.columnId)++ if (!row || columnIndex === -1) {+ resetAttachmentCellDropOver()+ return+ }++ const column = columns.value[columnIndex]!++ selection.value.clear()+ activeCell.value = {+ row: attachmentCellDropOver.value.rowIndex,+ column: columnIndex,+ path: attachmentCellDropOver.value.path,+ }++ handleCellDrop({+ files,+ e: event,+ row,+ column,+ })++ resetAttachmentCellDropOver()+}++const onOver = (files: File[] | null, e: DragEvent) => {+ const rect = canvasRef.value?.getBoundingClientRect()+ if (!rect) return++ if (+ clientMousePosition.clientX === e.clientX &&+ clientMousePosition.clientY === e.clientY &&+ mousePosition.x === e.clientX - rect.left &&+ mousePosition.y === e.clientY - rect.top+ ) {+ return+ }++ clientMousePosition.clientX = e.clientX+ clientMousePosition.clientY = e.clientY+ mousePosition.x = e.clientX - rect.left+ mousePosition.y = e.clientY - rect.top++ // Skip on hover on header+ if (mousePosition.y <= 32) {+ return resetAttachmentCellDropOver()+ }++ const element = elementMap.findElementAt(mousePosition.x, mousePosition.y, [ElementTypes.ROW])+ if (!element?.row) return++ const row = element?.row+ const rowIndex = element?.rowIndex+ const groupPath = generateGroupPath(element?.group)++ const { column } = findClickedColumn(mousePosition.x, scrollLeft.value)++ // If hover column is not attachment, skip+ if (!column || column.uidt !== UITypes.Attachment) {+ return resetAttachmentCellDropOver()+ }++ if (+ attachmentCellDropOver.value &&+ attachmentCellDropOver.value.rowIndex === rowIndex &&+ attachmentCellDropOver.value.columnId === column.id+ ) {+ return+ }++ attachmentCellDropOver.value = { rowIndex, columnId: column.id, path: groupPath, uploadingCells: [] }++ requestAnimationFrame(triggerRefreshCanvas)+}++useDropZone(canvasRef, { onDrop, onOver })+watch(removeInlineAddRecord,(newValue) => {diff --git a/packages/nc-gui/context/index.ts b/packages/nc-gui/context/index.tsindex 8bb3360784..a5a3542071 100644--- a/packages/nc-gui/context/index.ts+++ b/packages/nc-gui/context/index.ts@@ -131,7 +131,8 @@ export const ClientMousePositionInj: InjectionKey<Reactive<{ clientX: number; clexport const CanvasCellEventDataInj: InjectionKey<Reactive<{keyboardKey?: string- event?: KeyboardEvent | MouseEvent | PointerEvent+ files?: File[] | null+ event?: KeyboardEvent | MouseEvent | PointerEvent | DragEvent}>> = Symbol('canvas-cell-event-data-injection')diff --git a/packages/nc-gui/lib/types.ts b/packages/nc-gui/lib/types.tsindex 28c45c6191..acf3004402 100644--- a/packages/nc-gui/lib/types.ts+++ b/packages/nc-gui/lib/types.ts@@ -928,6 +928,13 @@ interface NcClipboardDataItemType {// NcClipboardDataType type ends here+interface AttachmentCellDropOverType {+ rowIndex?: number+ columnId: string+ path: Array<number>+ uploadingCells: Array<Omit<AttachmentCellDropOverType, 'uploadingCells'>>+}+export type {User,ProjectMetaInfo,@@ -995,4 +1002,5 @@ export type {CreateViewForm,NcClipboardDataType,NcClipboardDataItemType,+ AttachmentCellDropOverType,}