diff --git a/packages/ketcher-core/src/application/formatters/formatProperties.ts b/packages/ketcher-core/src/application/formatters/formatProperties.ts index 7653f650c8..6091eec922 100644 --- a/packages/ketcher-core/src/application/formatters/formatProperties.ts +++ b/packages/ketcher-core/src/application/formatters/formatProperties.ts @@ -94,6 +94,12 @@ const formatProperties: FormatPropertiesMap = { ChemicalMimeType.CDXML, ['.cdxml'], true + ), + cdx: new SupportedFormatProperties( + 'Base64 CDX', + ChemicalMimeType.CDX, + ['.cdx'], + true ) } diff --git a/packages/ketcher-core/src/application/formatters/formatterFactory.ts b/packages/ketcher-core/src/application/formatters/formatterFactory.ts index 9489fa2b09..76d7a810a7 100644 --- a/packages/ketcher-core/src/application/formatters/formatterFactory.ts +++ b/packages/ketcher-core/src/application/formatters/formatterFactory.ts @@ -91,6 +91,7 @@ export class FormatterFactory { case SupportedFormat.smilesExt: case SupportedFormat.smarts: case SupportedFormat.cdxml: + case SupportedFormat.cdx: default: formatter = new ServerFormatter( this.#structService, diff --git a/packages/ketcher-core/src/application/formatters/identifyStructFormat.ts b/packages/ketcher-core/src/application/formatters/identifyStructFormat.ts index 57dfa1f868..cad099b4a7 100644 --- a/packages/ketcher-core/src/application/formatters/identifyStructFormat.ts +++ b/packages/ketcher-core/src/application/formatters/identifyStructFormat.ts @@ -47,6 +47,7 @@ export function identifyStructFormat( return SupportedFormat.mol } } + if ( sanitizedString[0] === '<' && sanitizedString.indexOf(' { +function parseStruct( + struct: string | Struct, + server, + options? +): Promise { if (typeof struct === 'string') { options = options || {} const { rescale, fragment, ...formatterOptions } = options const format = identifyStructFormat(struct) + if (format === SupportedFormat.cdx) { + struct = `base64::${struct.replace(/\s/g, '')}` + } const factory = new FormatterFactory(server) const service = factory.create(format, formatterOptions) diff --git a/packages/ketcher-react/src/script/ui/utils/fileOpener.js b/packages/ketcher-react/src/script/ui/utils/fileOpener.js index d3baf9e921..c8762db815 100644 --- a/packages/ketcher-react/src/script/ui/utils/fileOpener.js +++ b/packages/ketcher-react/src/script/ui/utils/fileOpener.js @@ -40,11 +40,12 @@ export function fileOpener(server) { } function throughFileReader(file) { + const isCDX = file.name.endsWith('cdx') return new Promise((resolve, reject) => { const rd = new FileReader() // eslint-disable-line no-undef rd.onload = () => { - const content = rd.result + const content = isCDX ? rd.result.slice(37) : rd.result if (file.msClose) file.msClose() resolve(content) } @@ -52,8 +53,7 @@ function throughFileReader(file) { rd.onerror = (event) => { reject(event) } - - rd.readAsText(file, 'UTF-8') + isCDX ? rd.readAsDataURL(file) : rd.readAsText(file, 'UTF-8') }) } diff --git a/packages/ketcher-react/src/script/ui/views/modal/components/document/Save/Save.jsx b/packages/ketcher-react/src/script/ui/views/modal/components/document/Save/Save.jsx index 9834ec40f3..948676498e 100644 --- a/packages/ketcher-react/src/script/ui/views/modal/components/document/Save/Save.jsx +++ b/packages/ketcher-react/src/script/ui/views/modal/components/document/Save/Save.jsx @@ -88,6 +88,7 @@ class SaveDialog extends Component { 'svg', 'png', 'cdxml' + // 'cdx' TO DO: Uncomment, when export will be ready on Indigo side ) this.saveSchema = saveSchema diff --git a/packages/ketcher-standalone/src/infrastructure/services/struct/indigoWorker.types.ts b/packages/ketcher-standalone/src/infrastructure/services/struct/indigoWorker.types.ts index 73d2362f5d..07ba461f20 100644 --- a/packages/ketcher-standalone/src/infrastructure/services/struct/indigoWorker.types.ts +++ b/packages/ketcher-standalone/src/infrastructure/services/struct/indigoWorker.types.ts @@ -53,6 +53,7 @@ export enum SupportedFormat { InChI = 'inchi', InChIAuxInfo = 'inchi-aux', Ket = 'ket', + CDX = 'cdx', CDXML = 'cdxml' } diff --git a/packages/ketcher-standalone/src/infrastructure/services/struct/standaloneStructService.ts b/packages/ketcher-standalone/src/infrastructure/services/struct/standaloneStructService.ts index 88aa9e44bf..faa572c69d 100644 --- a/packages/ketcher-standalone/src/infrastructure/services/struct/standaloneStructService.ts +++ b/packages/ketcher-standalone/src/infrastructure/services/struct/standaloneStructService.ts @@ -112,6 +112,10 @@ function convertMimeTypeToOutputFormat( format = SupportedFormat.CDXML break } + case ChemicalMimeType.CDX: { + format = SupportedFormat.CDX + break + } default: { throw new Error('Unsupported chemical mime type') }