How to block setDataAtCell while user edits a cell (introduction to collaboration)

by handsoncode

HTML

<script src="https://cdn.jsdelivr.net/npm/handsontable@latest/dist/handsontable.full.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/handsontable@latest/dist/handsontable.full.min.css">
<script src="https://handsontable.com/docs/scripts/fixer.js"></script>
<div id="example"></div>

SCSS

p {
   font-family: Helvetica, sans-serif;
}

Babel + JSX

import Handsontable from 'handsontable';
import 'handsontable/dist/handsontable.full.min.css';
import {
  registerAllModules
} from 'handsontable/registry';

registerAllModules();

const example = document.getElementById('example');

const data = [
    ['Tesla', 2019, 'Black', 'Black'],
    ['Nissan', 2020, 'Blue', 'Blue'],
    ['Chrysler', 2022, 'Yellow', 'Black'],
    ['Volvo', 2021, 'White', 'Gray']
  ];

const hot = new Handsontable(example, {
  data: data,
  licenseKey: 'non-commercial-and-evaluation',
  rowHeaders: true,
  colHeaders: ['Car', 'Year', 'Chassis Color', 'Bumper Color'],
  stretchH: 'all',
  afterDocumentKeyDown: (e) => {
    console.log(hot.getActiveEditor()._opened);
  }
});

hot.selectCell(0, 0);

function waitForIt() {
  const id = setInterval(frame, 800);
  const state = hot.getActiveEditor();

  function frame() {
    if (!state) {
      clearInterval(id);

    } else if (state._opened === true) {
      console.log('I wait cause cell is being edited');

    } else if (state._opened === false) {
      console.log('I am closed');
      hot.setDataAtCell(3, 3, '**TEST**');
      clearInterval(id);
    }
  }
}

setTimeout(function() {
  waitForIt();
}, 2000);