partridgejiang / Kekule.js

A Javascript cheminformatics toolkit.
http://partridgejiang.github.io/Kekule.js
MIT License
247 stars 61 forks source link

onChange for Kekule Composer? #281

Open richardoptibrium opened 2 years ago

richardoptibrium commented 2 years ago

I'm looking for a way to set an onChange (or similar) event with the widget, there must be something similar in the code for example that enables the undo function?

I'd like to be able to set the smiles string in an external text box every time the design changes affecting the smiles string. Would really appreciate any help on this, I'm using the kekule composer widget.

Thanks in advance!

partridgejiang commented 1 year ago

Quite sorry that I hadn't notice this issue so far... The editObjsUpdated event can be used here, e.g.:

composer.getEditor().on('editObjsUpdated', function(e){
  let mol = Kekule.ChemStructureUtils.getTotalStructFragment(composer.getChemObj());
  if (mol)
    let smiles = Kekule.IO.saveMimeData(mol, 'chemical/x-daylight-smiles');
});