* Prepare text input to be displayed at given grid cell.
()
| 94 | * Prepare text input to be displayed at given grid cell. |
| 95 | */ |
| 96 | prepareEditor() { |
| 97 | if (this.activeEditor && this.activeEditor.isWaiting()) { |
| 98 | this.closeEditor(false, false, (dataSaved: boolean) => { |
| 99 | if (dataSaved) { |
| 100 | this.prepareEditor(); |
| 101 | } |
| 102 | }); |
| 103 | |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | const highlight = this.hot.getSelectedRangeActive()?.highlight; |
| 108 | |
| 109 | if (!highlight || highlight.isHeader()) { |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | const { row: rowNullable, col: colNullable } = highlight; |
| 114 | const row = rowNullable!; |
| 115 | const col = colNullable!; |
| 116 | const modifiedCellCoords = this.hot.runHooks<void | [number, number] | [number, number, number, number]>( |
| 117 | 'modifyGetCellCoords', row, col, false, 'meta' |
| 118 | ); |
| 119 | let visualRowToCheck = row; |
| 120 | let visualColumnToCheck = col; |
| 121 | |
| 122 | if (Array.isArray(modifiedCellCoords)) { |
| 123 | [visualRowToCheck, visualColumnToCheck] = modifiedCellCoords; |
| 124 | } |
| 125 | |
| 126 | // Getting values using the modified coordinates. |
| 127 | this.cellProperties = this.hot.getCellMeta(visualRowToCheck, visualColumnToCheck); |
| 128 | |
| 129 | if (!this.isCellEditable()) { |
| 130 | this.clearActiveEditor(); |
| 131 | |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | const td = this.hot.getCell(row, col, true); |
| 136 | |
| 137 | // Skip the preparation when the cell is not rendered in the DOM. The cell is scrolled out of |
| 138 | // the table's viewport. |
| 139 | if (td) { |
| 140 | const editorClass = this.hot.getCellEditor(this.cellProperties); |
| 141 | const prop = this.hot.colToProp(visualColumnToCheck); |
| 142 | const originalValue = |
| 143 | this.hot.getSourceDataAtCell(this.hot.toPhysicalRow(visualRowToCheck), visualColumnToCheck); |
| 144 | |
| 145 | this.activeEditor = getEditorInstance(editorClass, this.hot) as BaseEditor; |
| 146 | // Using not modified coordinates, as we need to get the table element using selection coordinates. |
| 147 | // There is an extra translation in the editor for saving value. |
| 148 | this.activeEditor.prepare(row, col, prop, td, originalValue, this.cellProperties); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Check is editor is opened/showed. |