partridgejiang / Kekule-React

React component wrapper for Kekule.js widgets.
MIT License
3 stars 2 forks source link

import error #1

Closed spencertr closed 1 year ago

spencertr commented 1 year ago

Hi, thank you for maintaing this wonderful library and sharing this code. I did a git clone and npm i and when i started up the app I got:

Failed to compile.

Module not found: Error: Can't resolve 'kekule-react' in '/Kekule-React/demo/src/components'
WARNING in ./node_modules/kekule/dist/kekule.js 626:60-67
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

I tried to do npm i kekule-react but that does not exist. I don't know where you are importing this from? Please assist, thanks.

partridgejiang commented 1 year ago

Hi @spencertr, thanks a lot for the reminding. I have made a version number mistake in the package.json which causes the failure of installation. Now the bug should be fixed, please try npm i kekule-react again, :).

spencertr commented 1 year ago

great, thanks @partridgejiang ! it's working now. another additional question, how do i get the smiles string from the composer? in your docs it states:

// Get all molecules inside editor
var mols = getComposer().exportObjs(Kekule.Molecule);

I tried this.composer.exportObjs(Kekule.Molecule) however I got, this.composer.exportObjs is not a function. Is there a different method to call?

partridgejiang commented 1 year ago

this.composer is just a React Component wrapper object, to access the real Kekule widget inside it, you'll need to call the getWidget method of React wrapper:

let composerWidget = this.composer.getWidget();
let mols = getComposer().exportObjs(Kekule.Molecule);
let smiles = Kekule.IO.saveFormatData(mols[0], 'smi');
spencertr commented 1 year ago

thanks for explanation. however, when i tried your code i got:

ERROR in [eslint]
src/components/ComposerViewer.js
  Line 90:15:  'getComposer' is not defined  no-undef

I don't see where composerWidget is being used after you declare it on the first line. Thanks for responses!

partridgejiang commented 1 year ago

Oops, a typo there, should be:

let composerWidget = this.composer.current.getWidget();
let mols = composerWidget.exportObjs(Kekule.Molecule);
let smiles = Kekule.IO.saveFormatData(mols[0], 'smi');
spencertr commented 1 year ago

great, thanks, working now. I just added, this.composer.current.getWdiget() and it works. Btw, I used your library for a personal project back in 2017. Now I am using your library for a work-related project. Thanks for all your hard work on this!

partridgejiang commented 1 year ago

Glad to do some little help to your work as well, :).