various fixes

This commit is contained in:
bkfox
2022-12-12 12:29:05 +01:00
parent a53a37021c
commit d2a65bd1fe
9 changed files with 282 additions and 200 deletions

View File

@ -16,6 +16,7 @@
<template v-for="(item,row) in items" :key="row">
<!-- data-index comes from AList component drag & drop -->
<a-row :item="item" :cell="{row}" :columns="columns" :data-index="row"
:data-row="row"
:draggable="orderable"
@dragstart="onDragStart" @dragover="onDragOver" @drop="onDrop"
@cell="onCellEvent(row, $event)">
@ -24,7 +25,7 @@
<slot :name="name" v-bind="data"/>
</template>
<template v-else>
<div @keydown.ctrl="onControlKey($event, data.cell)">
<div>
<slot :name="name" v-bind="data"/>
</div>
</template>
@ -64,12 +65,7 @@ const Component = {
for(var row in this.items)
cells.push({row})
},
rows() {
return [...this.$el.querySelectorAll('tr')].filter(x => x.__row)
.map(x => x.__row)
},
rowSlots() {
return Object.keys(this.$slots).filter(x => x.startsWith('row-'))
.map(x => [x, x.slice(4)])
@ -77,27 +73,6 @@ const Component = {
},
methods: {
onControlKey(event, cell) {
switch(event.key) {
case "ArrowUp": this.focus(-1, 0, cell)
event.stopPropagation()
event.preventDefault()
break;
case "ArrowDown": this.focus(1, 0, cell)
event.stopPropagation()
event.preventDefault()
break;
case "ArrowLeft": this.focus(0, -1, cell)
event.stopPropagation()
event.preventDefault()
break;
case "ArrowRight": this.focus(0, 1, cell)
event.stopPropagation()
event.preventDefault()
break;
}
},
/**
* React on 'cell' event, re-emitting it with additional values:
* - `set`: data set
@ -108,27 +83,30 @@ const Component = {
*/
onCellEvent(row, event) {
if(event.name == 'focus')
this.cellFocus(event.data, event.cell)
this.focus(event.data, event.cell)
this.$emit('cell', {
...event, row,
set: this.set
})
},
getCellNode(row, col) {
const el = this.$refs[row]
return el && el.cellEls(col)
/**
* Return row component at provided index
*/
getRow(row) {
const els = this.$el.querySelectorAll('tr')
for(var el of els)
if(el.__row && row == Number(el.dataset.row))
return el.__row
},
/**
/**
* Focus on a cell
*/
focus(row, col, from=null) {
if(from)
row += from.row
row = this.rows[row]
row = this.getRow(row)
row && row.focus(col, from)
},
},