import { XMLTextElement } from 'substance'

export default class TableCellNode extends XMLTextElement {
  constructor (...args) {
    super(...args)

    this.rowIdx = -1
    this.colIdx = -1
  }

  get rowspan () {
    return _parseSpan(this.getAttribute('rowspan'))
  }

  get colspan () {
    return _parseSpan(this.getAttribute('colspan'))
  }

  isShadowed () {
    return this.shadowed
  }

  getMasterCell () {
    return this.masterCell
  }
}

TableCellNode.type = 'table-cell'

function _parseSpan (str) {
  let span = parseInt(str, 10)
  if (isFinite(span)) {
    return Math.max(span, 1)
  } else {
    return 1
  }
}

@@ -35,16 +35,46 @@
 bstance'
+%0Aimport %7B TEXT %7D from '../kit'
 %0A%0Aexport
@@ -510,16 +510,143 @@
 -cell'%0A%0A
+TableCellNode.schema = %7B%0A  content: TEXT('bold', 'italic', 'sup', 'sub', 'monospace', 'ext-link', 'xref', 'inline-formula')%0A%7D%0A%0A
 function

Allow annotations and inline-nodes in TableCells.