| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.ce.TableRowNode = function VeCeTableRowNode() { |
| 17 |
|
| 18 |
ve.ce.TableRowNode.super.apply( this, arguments ); |
| 19 |
|
| 20 |
this.$missingCell = null; |
| 21 |
}; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
OO.inheritClass( ve.ce.TableRowNode, ve.ce.BranchNode ); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
ve.ce.TableRowNode.static.name = 'tableRow'; |
| 30 |
|
| 31 |
ve.ce.TableRowNode.static.tagName = 'tr'; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
ve.ce.TableRowNode.prototype.onSetup = function () { |
| 39 |
|
| 40 |
ve.ce.TableRowNode.super.prototype.onSetup.apply( this, arguments ); |
| 41 |
|
| 42 |
this.setupMissingCell(); |
| 43 |
}; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
ve.ce.TableRowNode.prototype.onSplice = function () { |
| 49 |
|
| 50 |
ve.ce.TableRowNode.super.prototype.onSplice.apply( this, arguments ); |
| 51 |
|
| 52 |
|
| 53 |
setTimeout( () => { |
| 54 |
if ( this.getRoot() ) { |
| 55 |
|
| 56 |
|
| 57 |
this.setupMissingCell(); |
| 58 |
} |
| 59 |
} ); |
| 60 |
}; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
ve.ce.TableRowNode.prototype.setupMissingCell = function () { |
| 66 |
const matrix = this.findParent( ve.ce.TableNode ).getModel().getMatrix(), |
| 67 |
maxColCount = matrix.getMaxColCount(); |
| 68 |
|
| 69 |
const row = matrix.getRowNodes().indexOf( this.model ); |
| 70 |
if ( maxColCount > matrix.getColCount( row ) ) { |
| 71 |
if ( !this.$missingCell ) { |
| 72 |
this.$missingCell = $( '<td>' ) |
| 73 |
.prop( 'contentEditable', 'false' ) |
| 74 |
.addClass( 've-ce-branchNode-slug ve-ce-branchNode-blockSlug ve-ce-tableNode-missingCell' ); |
| 75 |
const slugButton = new ve.ui.NoFocusButtonWidget( { |
| 76 |
icon: 'add', |
| 77 |
framed: false |
| 78 |
} ).on( 'click', this.onMissingCellClick.bind( this ) ); |
| 79 |
this.$missingCell.append( slugButton.$element ); |
| 80 |
} |
| 81 |
this.$element.append( this.$missingCell ); |
| 82 |
} else { |
| 83 |
this.removeSlugs(); |
| 84 |
} |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
ve.ce.TableRowNode.prototype.removeSlugs = function () { |
| 91 |
if ( this.$missingCell ) { |
| 92 |
this.$missingCell.detach(); |
| 93 |
} |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
ve.ce.TableRowNode.prototype.onMissingCellClick = function () { |
| 102 |
const surfaceModel = this.getRoot().getSurface().getModel(), |
| 103 |
documentModel = surfaceModel.getDocument(), |
| 104 |
tableModel = this.findParent( ve.ce.TableNode ).getModel(), |
| 105 |
matrix = tableModel.getMatrix(); |
| 106 |
|
| 107 |
|
| 108 |
surfaceModel.change( |
| 109 |
ve.dm.TransactionBuilder.static.newFromInsertion( |
| 110 |
documentModel, this.getModel().getRange().end, |
| 111 |
ve.dm.TableCellNode.static.createData() |
| 112 |
) |
| 113 |
); |
| 114 |
|
| 115 |
|
| 116 |
const row = matrix.getRowNodes().indexOf( this.model ); |
| 117 |
const col = matrix.getColCount( row ) - 1; |
| 118 |
surfaceModel.setSelection( |
| 119 |
new ve.dm.TableSelection( tableModel.getOuterRange(), col, row ) |
| 120 |
); |
| 121 |
}; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
ve.ce.nodeFactory.register( ve.ce.TableRowNode ); |