Commit 72f804dd authored by Mab's avatar Mab

update table

parent f8b9319c
import { Component } from 'substance'
import { uuid, Component } from 'substance'
import TableCellComponent from './TableCellComponent'
import ButtonAddCollComponent from './ButtonAddCollComponent'
class TableComponent extends Component {
render($$) {
......@@ -9,6 +10,21 @@ class TableComponent extends Component {
let cells = this.props.node.cells
let rowCount = node.getRowCount()
let colCount = node.getColCount()
let rowEl = $$('tr')
let newNode = doc.create({
id: uuid('table-cell'),
type: 'table-cell',
content: '',
})
let newCell = $$(ButtonAddCollComponent, {
node: newNode,
disabled: this.props.disabled,
addCol: this.addRowUpSide.bind(this),
}).ref(newNode.id)
rowEl.append(newCell)
el.append(rowEl)
for (let i = 0; i < rowCount; i++) {
let rowEl = $$('tr')
for (let j = 0; j < colCount; j++) {
......@@ -23,13 +39,122 @@ class TableComponent extends Component {
rowEl.append(cellEl)
}
}
if (i == rowCount - 1) {
let newNode = doc.create({
id: uuid('table-cell'),
type: 'table-cell',
content: '',
})
let newCell = $$(ButtonAddCollComponent, {
node: newNode,
disabled: this.props.disabled,
addCol: this.addColLeftSide.bind(this),
}).ref(newNode.id)
rowEl.append(newCell)
}
el.append(rowEl)
}
let rowEl_bis = $$('tr')
let newNode_ter = doc.create({
id: uuid('table-cell'),
type: 'table-cell',
content: '',
})
let newCell_ter = $$(ButtonAddCollComponent, {
node: newNode_ter,
disabled: this.props.disabled,
addCol: this.addColRightSide.bind(this),
right: true,
}).ref(newNode_ter.id)
console.log(newCell_ter)
rowEl_bis.append(newCell_ter)
let newNode_bis = doc.create({
id: uuid('table-cell'),
type: 'table-cell',
content: '',
})
let newCell_bis = $$(ButtonAddCollComponent, {
node: newNode_bis,
disabled: this.props.disabled,
addCol: this.addRowDownSide.bind(this),
}).ref(newNode_bis.id)
rowEl_bis.append(newCell_bis)
el.append(rowEl_bis)
el.on('click', this.onClick)
el.on('dblclick', this.onDblClick)
return el
}
addColRightSide() {
let node = this.props.node
let doc = this.props.node.getDocument()
let cells = this.props.node.cells
let rowCount = node.getRowCount()
for (let i = 0; i < rowCount; i++) {
let newNode = doc.create({
id: uuid('table-cell'),
type: 'table-cell',
content: '',
})
cells[i].unshift(newNode.id)
}
this.rerender()
}
addColLeftSide() {
let node = this.props.node
let doc = this.props.node.getDocument()
let cells = this.props.node.cells
let rowCount = node.getRowCount()
for (let i = 0; i < rowCount; i++) {
let newNode = doc.create({
id: uuid('table-cell'),
type: 'table-cell',
content: '',
})
cells[i].push(newNode.id)
}
this.rerender()
}
addRowUpSide(event){
let node = this.props.node
let doc = this.props.node.getDocument()
let cells = this.props.node.cells
let colCount = node.getColCount()
let newRow = []
for (let i = 0; i < colCount; i++) {
let newNode = doc.create({
id: uuid('table-cell'),
type: 'table-cell',
content: '',
})
newRow.push(newNode.id)
}
cells.unshift(newRow)
this.rerender()
}
addRowDownSide(event){
let node = this.props.node
let doc = this.props.node.getDocument()
let cells = this.props.node.cells
let colCount = node.getColCount()
let newRow = []
for (let i = 0; i < colCount; i++) {
let newNode = doc.create({
id: uuid('table-cell'),
type: 'table-cell',
content: '',
})
newRow.push(newNode.id)
}
cells.push(newRow)
this.rerender()
}
onClick(event) {
event.stopPropagation()
// console.log('Clicked on Table', this.props.node.id, event.target)
......
......@@ -15,17 +15,20 @@ export default {
config.addConverter('html', TableCellHTMLConverter)
config.addCommand('insert-table', InsertTableCommand, {
nodeType: 'table',
commandGroup: 'insert',
commandGroup: 'insert-table',
})
config.addIcon('insert-table', { fontawesome: 'fa-table' })
config.addLabel('insert-table', {
en: 'Table',
fr: 'Insérer un tableau'
})
config.addLabel('table', {
en: 'Table',
fr: 'Tableau'
})
config.addLabel('table-cell.content', {
en: 'Cell',
fr: 'Cellule'
})
},
Table,
......
......@@ -13,6 +13,7 @@ export default {
'insert-strong',
'annotations',
'insert-image',
'insert-table',
'note',
'list',
'find-and-replace-tool',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment