-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
96 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import OCL from '../../../distesm/full.pretty'; | ||
import { | ||
incrementChangeCount, | ||
resetChangeCount, | ||
updateIDCode, | ||
updateMolfile, | ||
} from './result.ts'; | ||
|
||
let editor: OCL.CanvasEditor | undefined; | ||
|
||
export function resetEditor() { | ||
if (editor) { | ||
editor.destroy(); | ||
} | ||
const modeSelect = document.getElementById('modeSelect') as HTMLSelectElement; | ||
const newEditor = new OCL.CanvasEditor( | ||
document.getElementById('editor') as HTMLElement, | ||
{ | ||
initialMode: modeSelect.value as OCL.CanvasEditorMode, | ||
}, | ||
); | ||
|
||
editor = newEditor; | ||
|
||
resetChangeCount(); | ||
|
||
editor.setOnChangeListener(({ type, isUserEvent }) => { | ||
if (type === 'molecule') { | ||
if (isUserEvent) { | ||
incrementChangeCount(); | ||
} | ||
updateIDCode(newEditor.getMolecule()); | ||
updateMolfile(newEditor.getMolecule()); | ||
} | ||
}); | ||
} | ||
|
||
export function getEditor(): OCL.CanvasEditor { | ||
if (!editor) { | ||
throw new Error('Editor not initialized'); | ||
} | ||
return editor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import OCL from '../../../distesm/full.pretty'; | ||
|
||
const changeCountDiv = document.getElementById('changeCount') as HTMLElement; | ||
|
||
export function incrementChangeCount() { | ||
const currentChangeCount = parseInt(changeCountDiv.innerText, 10); | ||
changeCountDiv.innerText = String(currentChangeCount + 1); | ||
} | ||
|
||
export function resetChangeCount() { | ||
changeCountDiv.innerText = '0'; | ||
} | ||
|
||
const idcodeDiv = document.getElementById('idcode') as HTMLElement; | ||
|
||
export function updateIDCode(molecule: OCL.Molecule) { | ||
const idcodeAndCoords = molecule.getIDCodeAndCoordinates(); | ||
idcodeDiv.innerText = `${idcodeAndCoords.idCode} ${idcodeAndCoords.coordinates}`; | ||
} | ||
|
||
const molfileDiv = document.getElementById('molfile') as HTMLElement; | ||
|
||
export function updateMolfile(molecule: OCL.Molecule) { | ||
molfileDiv.innerText = molecule.toMolfileV3(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters