|
|
|
@ -1,12 +1,14 @@
|
|
|
|
|
<script lang="ts" setup> |
|
|
|
|
import { isVirtualCol } from 'nocodb-sdk' |
|
|
|
|
import { ColumnType, isVirtualCol } from 'nocodb-sdk' |
|
|
|
|
import { |
|
|
|
|
Row, |
|
|
|
|
inject, |
|
|
|
|
onKeyStroke, |
|
|
|
|
onMounted, |
|
|
|
|
provide, |
|
|
|
|
useGridViewColumnWidth, |
|
|
|
|
useProvideColumnCreateStore, |
|
|
|
|
useSmartsheetStoreOrThrow, |
|
|
|
|
useViewData, |
|
|
|
|
} from '#imports' |
|
|
|
|
import { |
|
|
|
@ -16,36 +18,55 @@ import {
|
|
|
|
|
FieldsInj, |
|
|
|
|
IsFormInj, |
|
|
|
|
IsGridInj, |
|
|
|
|
IsLockedInj, |
|
|
|
|
MetaInj, |
|
|
|
|
PaginationDataInj, |
|
|
|
|
ReloadViewDataHookInj, |
|
|
|
|
} from '~/context' |
|
|
|
|
import MdiPlusIcon from '~icons/mdi/plus' |
|
|
|
|
import MdiArrowExpandIcon from '~icons/mdi/arrow-expand' |
|
|
|
|
|
|
|
|
|
const meta = inject(MetaInj) |
|
|
|
|
const view = inject(ActiveViewInj) |
|
|
|
|
// keep a root fields variable and will get modified from |
|
|
|
|
// fields menu and get used in grid and gallery |
|
|
|
|
const fields = inject(FieldsInj) |
|
|
|
|
|
|
|
|
|
const fields = inject(FieldsInj, ref([])) |
|
|
|
|
const isLocked = inject(IsLockedInj, false) |
|
|
|
|
// todo: get from parent ( inject or use prop ) |
|
|
|
|
const isPublicView = false |
|
|
|
|
|
|
|
|
|
const selected = reactive<{ row?: number | null; col?: number | null }>({}) |
|
|
|
|
const editEnabled = ref(false) |
|
|
|
|
const selected = reactive<{ row: number | null; col: number | null }>({ row: null, col: null }) |
|
|
|
|
let editEnabled = $ref(false) |
|
|
|
|
const { sqlUi } = useProject() |
|
|
|
|
const { xWhere } = useSmartsheetStoreOrThrow() |
|
|
|
|
const addColumnDropdown = ref(false) |
|
|
|
|
const contextMenu = ref(false) |
|
|
|
|
const contextMenuTarget = ref(false) |
|
|
|
|
|
|
|
|
|
const visibleColLength = $computed(() => { |
|
|
|
|
const cols = fields.value |
|
|
|
|
return cols.filter((col) => !isVirtualCol(col)).length |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const { loadData, paginationData, formattedData: data, updateRowProperty, changePage } = useViewData(meta, view as any, xWhere) |
|
|
|
|
const { loadGridViewColumns, updateWidth, resizingColWidth, resizingCol } = useGridViewColumnWidth(view) |
|
|
|
|
const { |
|
|
|
|
loadData, |
|
|
|
|
paginationData, |
|
|
|
|
formattedData: data, |
|
|
|
|
updateOrSaveRow, |
|
|
|
|
changePage, |
|
|
|
|
addEmptyRow, |
|
|
|
|
deleteRow, |
|
|
|
|
deleteSelectedRows, |
|
|
|
|
selectedAllRecords, |
|
|
|
|
} = useViewData(meta, view as any, xWhere) |
|
|
|
|
const { loadGridViewColumns, updateWidth, resizingColWidth, resizingCol } = useGridViewColumnWidth(view as any) |
|
|
|
|
onMounted(loadGridViewColumns) |
|
|
|
|
|
|
|
|
|
provide(IsFormInj, false) |
|
|
|
|
provide(IsGridInj, true) |
|
|
|
|
provide(PaginationDataInj, paginationData) |
|
|
|
|
provide(ChangePageInj, changePage) |
|
|
|
|
provide(EditModeInj, editEnabled) |
|
|
|
|
provide(ChangePageInj, changePage) |
|
|
|
|
|
|
|
|
|
const reloadViewDataHook = inject(ReloadViewDataHookInj) |
|
|
|
|
reloadViewDataHook?.on(() => { |
|
|
|
@ -59,7 +80,7 @@ const selectCell = (row: number, col: number) => {
|
|
|
|
|
|
|
|
|
|
onKeyStroke(['Enter'], (e) => { |
|
|
|
|
if (selected.row !== null && selected.col !== null) { |
|
|
|
|
editEnabled.value = true |
|
|
|
|
editEnabled = true |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -89,75 +110,200 @@ defineExpose({
|
|
|
|
|
// watchEffect(() => { |
|
|
|
|
if (meta) useProvideColumnCreateStore(meta) |
|
|
|
|
// }) |
|
|
|
|
|
|
|
|
|
// reset context menu target on hide |
|
|
|
|
watch(contextMenu, () => { |
|
|
|
|
if (!contextMenu.value) { |
|
|
|
|
contextMenuTarget.value = false |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const clearCell = async (ctx: { row: number; col: number }) => { |
|
|
|
|
const rowObj = data.value[ctx.row] |
|
|
|
|
const columnObj = fields.value[ctx.col] |
|
|
|
|
|
|
|
|
|
if (isVirtualCol(columnObj)) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rowObj.row[columnObj.title] = null |
|
|
|
|
// update/save cell value |
|
|
|
|
await updateOrSaveRow(rowObj, columnObj.title) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** handle keypress events */ |
|
|
|
|
onKeyStroke(['Tab', 'Shift', 'Enter', 'Delete', 'ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight'], async (e: KeyboardEvent) => { |
|
|
|
|
if (selected.row !== null && selected.col !== null) { |
|
|
|
|
/** on tab key press navigate through cells */ |
|
|
|
|
switch (e.key) { |
|
|
|
|
case 'Tab': |
|
|
|
|
e.preventDefault() |
|
|
|
|
if (e.shiftKey) { |
|
|
|
|
if (selected.col > 0) { |
|
|
|
|
selected.col-- |
|
|
|
|
} else if (selected.row > 0) { |
|
|
|
|
selected.row-- |
|
|
|
|
selected.col = visibleColLength - 1 |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (selected.col < visibleColLength - 1) { |
|
|
|
|
selected.col++ |
|
|
|
|
} else if (selected.row < data.value.length - 1) { |
|
|
|
|
selected.row++ |
|
|
|
|
selected.col = 0 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break |
|
|
|
|
/** on enter key press make cell editable */ |
|
|
|
|
case 'Enter': |
|
|
|
|
e.preventDefault() |
|
|
|
|
editEnabled = true |
|
|
|
|
break |
|
|
|
|
/** on delete key press clear cell */ |
|
|
|
|
case 'Delete': |
|
|
|
|
e.preventDefault() |
|
|
|
|
await clearCell(selected as { row: number; col: number }) |
|
|
|
|
break |
|
|
|
|
/** on arrow key press navigate through cells */ |
|
|
|
|
case 'ArrowRight': |
|
|
|
|
e.preventDefault() |
|
|
|
|
if (selected.col < visibleColLength - 1) selected.col++ |
|
|
|
|
break |
|
|
|
|
case 'ArrowLeft': |
|
|
|
|
e.preventDefault() |
|
|
|
|
if (selected.col > 0) selected.col-- |
|
|
|
|
break |
|
|
|
|
case 'ArrowUp': |
|
|
|
|
e.preventDefault() |
|
|
|
|
if (selected.row > 0) selected.row-- |
|
|
|
|
break |
|
|
|
|
case 'ArrowDown': |
|
|
|
|
e.preventDefault() |
|
|
|
|
if (selected.row < data.value.length - 1) selected.row++ |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<template> |
|
|
|
|
<div class="flex flex-col h-100 min-h-0 w-100"> |
|
|
|
|
<div class="nc-grid-wrapper min-h-0 flex-1 scrollbar-thin-primary"> |
|
|
|
|
<table class="xc-row-table nc-grid backgroundColorDefault"> |
|
|
|
|
<thead> |
|
|
|
|
<tr> |
|
|
|
|
<th>#</th> |
|
|
|
|
<th |
|
|
|
|
v-for="col in fields" |
|
|
|
|
:key="col.title" |
|
|
|
|
v-xc-ver-resize |
|
|
|
|
:data-col="col.id" |
|
|
|
|
@xcresize="onresize(col.id, $event)" |
|
|
|
|
@xcresizing="onXcResizing(col.title, $event)" |
|
|
|
|
@xcresized="resizingCol = null" |
|
|
|
|
> |
|
|
|
|
<SmartsheetHeaderVirtualCell v-if="isVirtualCol(col)" :column="col" /> |
|
|
|
|
<SmartsheetHeaderCell v-else :column="col" /> |
|
|
|
|
</th> |
|
|
|
|
<!-- v-if="!isLocked && !isVirtual && !isPublicView && _isUIAllowed('add-column')" --> |
|
|
|
|
<th v-t="['c:column:add']" @click="addColumnDropdown = true"> |
|
|
|
|
<a-dropdown v-model:visible="addColumnDropdown" :trigger="['click']"> |
|
|
|
|
<div class="h-full w-full flex align-center justify-center"> |
|
|
|
|
<MdiPlusIcon class="text-sm" /> |
|
|
|
|
<a-dropdown v-model:visible="contextMenu" :trigger="['contextmenu']"> |
|
|
|
|
<table class="xc-row-table nc-grid backgroundColorDefault" @contextmenu.prevent="contextMenu = true"> |
|
|
|
|
<thead> |
|
|
|
|
<tr class="group"> |
|
|
|
|
<th> |
|
|
|
|
<div class="flex align-center w-[80px]"> |
|
|
|
|
<div class="group-hover:hidden" :class="{ hidden: selectedAllRecords }">#</div> |
|
|
|
|
<div |
|
|
|
|
:class="{ hidden: !selectedAllRecords, flex: selectedAllRecords }" |
|
|
|
|
class="group-hover:flex w-full align-center" |
|
|
|
|
> |
|
|
|
|
<a-checkbox v-model:checked="selectedAllRecords" /> |
|
|
|
|
<span class="flex-1" /> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</th> |
|
|
|
|
<th |
|
|
|
|
v-for="col in fields" |
|
|
|
|
:key="col.title" |
|
|
|
|
v-xc-ver-resize |
|
|
|
|
:data-col="col.id" |
|
|
|
|
@xcresize="onresize(col.id, $event)" |
|
|
|
|
@xcresizing="onXcResizing(col.title, $event)" |
|
|
|
|
@xcresized="resizingCol = null" |
|
|
|
|
> |
|
|
|
|
<SmartsheetHeaderVirtualCell v-if="isVirtualCol(col)" :column="col" /> |
|
|
|
|
<SmartsheetHeaderCell v-else :column="col" /> |
|
|
|
|
</th> |
|
|
|
|
<!-- v-if="!isLocked && !isVirtual && !isPublicView && _isUIAllowed('add-column')" --> |
|
|
|
|
<th v-t="['c:column:add']" @click="addColumnDropdown = true"> |
|
|
|
|
<a-dropdown v-model:visible="addColumnDropdown" :trigger="['click']"> |
|
|
|
|
<div class="h-full w-full flex align-center justify-center"> |
|
|
|
|
<MdiPlusIcon class="text-sm" /> |
|
|
|
|
</div> |
|
|
|
|
<template #overlay> |
|
|
|
|
<SmartsheetColumnEditOrAdd @click.stop @cancel="addColumnDropdown = false" /> |
|
|
|
|
</template> |
|
|
|
|
</a-dropdown> |
|
|
|
|
</th> |
|
|
|
|
</tr> |
|
|
|
|
</thead> |
|
|
|
|
<tbody> |
|
|
|
|
<tr v-for="(row, rowIndex) in data" :key="rowIndex" class="nc-grid-row group"> |
|
|
|
|
<td key="row-index" class="caption nc-grid-cell"> |
|
|
|
|
<div class="align-center flex w-[80px]"> |
|
|
|
|
<div class="group-hover:hidden" :class="{ hidden: row.rowMeta.selected }">{{ rowIndex + 1 }}</div> |
|
|
|
|
<div |
|
|
|
|
:class="{ hidden: !row.rowMeta.selected, flex: row.rowMeta.selected }" |
|
|
|
|
class="group-hover:flex w-full align-center" |
|
|
|
|
> |
|
|
|
|
<a-checkbox v-model:checked="row.rowMeta.selected" /> |
|
|
|
|
<span class="flex-1" /> |
|
|
|
|
<MdiArrowExpandIcon class="text-sm text-pink hidden group-hover:inline-block" /> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<template #overlay> |
|
|
|
|
<SmartsheetColumnEditOrAdd @click.stop @cancel="addColumnDropdown = false" /> |
|
|
|
|
</template> |
|
|
|
|
</a-dropdown> |
|
|
|
|
</th> |
|
|
|
|
</tr> |
|
|
|
|
</thead> |
|
|
|
|
<tbody> |
|
|
|
|
<tr v-for="({ row }, rowIndex) in data" :key="rowIndex" class="nc-grid-row"> |
|
|
|
|
<td key="row-index" style="width: 65px" class="caption nc-grid-cell"> |
|
|
|
|
<div class="d-flex align-center"> |
|
|
|
|
{{ rowIndex + 1 }} |
|
|
|
|
</div> |
|
|
|
|
</td> |
|
|
|
|
<td |
|
|
|
|
v-for="(columnObj, colIndex) in fields" |
|
|
|
|
:key="rowIndex + columnObj.title" |
|
|
|
|
class="cell pointer nc-grid-cell" |
|
|
|
|
:class="{ |
|
|
|
|
active: !isPublicView && selected.col === colIndex && selected.row === rowIndex, |
|
|
|
|
// 'primary-column': primaryValueColumn === columnObj.title, |
|
|
|
|
// 'text-center': isCentrallyAligned(columnObj), |
|
|
|
|
// 'required': isRequired(columnObj, rowObj), |
|
|
|
|
}" |
|
|
|
|
:data-col="columnObj.id" |
|
|
|
|
@click="selectCell(rowIndex, colIndex)" |
|
|
|
|
@dblclick="editEnabled = true" |
|
|
|
|
> |
|
|
|
|
<SmartsheetVirtualCell v-if="isVirtualCol(columnObj)" v-model="row[columnObj.title]" :column="columnObj" /> |
|
|
|
|
|
|
|
|
|
<SmartsheetCell |
|
|
|
|
v-else |
|
|
|
|
v-model="row[columnObj.title]" |
|
|
|
|
:column="columnObj" |
|
|
|
|
:edit-enabled="editEnabled && selected.col === colIndex && selected.row === rowIndex" |
|
|
|
|
@update:model-value="updateRowProperty(row, columnObj.title)" |
|
|
|
|
/> |
|
|
|
|
</td> |
|
|
|
|
</tr> |
|
|
|
|
</tbody> |
|
|
|
|
</table> |
|
|
|
|
</td> |
|
|
|
|
<td |
|
|
|
|
v-for="(columnObj, colIndex) in fields" |
|
|
|
|
:key="rowIndex + columnObj.title" |
|
|
|
|
class="cell pointer nc-grid-cell" |
|
|
|
|
:class="{ |
|
|
|
|
active: !isPublicView && selected.col === colIndex && selected.row === rowIndex, |
|
|
|
|
}" |
|
|
|
|
:data-col="columnObj.id" |
|
|
|
|
@click="selectCell(rowIndex, colIndex)" |
|
|
|
|
@dblclick="editEnabled = true" |
|
|
|
|
@contextmenu="contextMenuTarget = { row: rowIndex, col: colIndex }" |
|
|
|
|
> |
|
|
|
|
<SmartsheetVirtualCell v-if="isVirtualCol(columnObj)" v-model="row.row[columnObj.title]" :column="columnObj" /> |
|
|
|
|
|
|
|
|
|
<SmartsheetCell |
|
|
|
|
v-else |
|
|
|
|
v-model="row.row[columnObj.title]" |
|
|
|
|
:column="columnObj" |
|
|
|
|
:edit-enabled="editEnabled && selected.col === colIndex && selected.row === rowIndex" |
|
|
|
|
@save="updateOrSaveRow(row, columnObj.title)" |
|
|
|
|
/> |
|
|
|
|
</td> |
|
|
|
|
</tr> |
|
|
|
|
|
|
|
|
|
<tr v-if="!isLocked"> |
|
|
|
|
<td |
|
|
|
|
v-t="['c:row:add:grid-bottom']" |
|
|
|
|
:colspan="visibleColLength + 1" |
|
|
|
|
class="text-left pointer nc-grid-add-new-cell" |
|
|
|
|
@click="addEmptyRow()" |
|
|
|
|
> |
|
|
|
|
<a-tooltip top left> |
|
|
|
|
<div class="w-min flex align-center"> |
|
|
|
|
<MdiPlusIcon class="text-pint-500 text-xs" /> |
|
|
|
|
<span class="ml-1 caption grey--text"> |
|
|
|
|
{{ $t('activity.addRow') }} |
|
|
|
|
</span> |
|
|
|
|
</div> |
|
|
|
|
<template #title> |
|
|
|
|
<span class="caption"> Add new row</span> |
|
|
|
|
</template> |
|
|
|
|
</a-tooltip> |
|
|
|
|
</td> |
|
|
|
|
</tr> |
|
|
|
|
</tbody> |
|
|
|
|
</table> |
|
|
|
|
<template #overlay> |
|
|
|
|
<div class="bg-white shadow" @click="contextMenu = false"> |
|
|
|
|
<div v-if="contextMenuTarget" class="nc-menu-item" @click="deleteRow(contextMenuTarget.row)">Delete row</div> |
|
|
|
|
<div class="nc-menu-item" @click="deleteSelectedRows">Delete all selected rows</div> |
|
|
|
|
<div v-if="contextMenuTarget" class="nc-menu-item" @click="clearCell(contextMenuTarget)">Clear cell</div> |
|
|
|
|
<div v-if="contextMenuTarget" class="nc-menu-item" @click="addEmptyRow(contextMenuTarget.row + 1)"> |
|
|
|
|
Insert new row |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</template> |
|
|
|
|
</a-dropdown> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<SmartsheetPagination /> |
|
|
|
|
</div> |
|
|
|
|
</template> |
|
|
|
@ -175,6 +321,11 @@ if (meta) useProvideColumnCreateStore(meta)
|
|
|
|
|
height: 41px !important; |
|
|
|
|
position: relative; |
|
|
|
|
padding: 0 5px; |
|
|
|
|
|
|
|
|
|
& > * { |
|
|
|
|
@apply flex align-center h-auto; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
overflow: hidden; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -186,8 +337,6 @@ if (meta) useProvideColumnCreateStore(meta)
|
|
|
|
|
border-bottom: 1px solid #7f828b33 !important; |
|
|
|
|
border-top: 1px solid #7f828b33 !important; |
|
|
|
|
border-collapse: collapse; |
|
|
|
|
|
|
|
|
|
font-size: 0.8rem; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
td { |
|
|
|
|