diff --git a/packages/ketcher-core/__tests__/domain/serializers/ket/fixtures/toKet.ts b/packages/ketcher-core/__tests__/domain/serializers/ket/fixtures/toKet.ts index 40d47fd36b..95e9a32d3d 100644 --- a/packages/ketcher-core/__tests__/domain/serializers/ket/fixtures/toKet.ts +++ b/packages/ketcher-core/__tests__/domain/serializers/ket/fixtures/toKet.ts @@ -13,6 +13,8 @@ import { Text } from 'domain/entities' +import { getNodeWithInvertedYCoord } from 'domain/serializers/ket/helpers' + const structs = { prepareContent: { atoms: [ @@ -1452,17 +1454,19 @@ const initStruct = (structName) => { break case 'rxnArrows': structData.rxnArrows.forEach((props) => - struct.rxnArrows.add(new RxnArrow(props)) + struct.rxnArrows.add(new RxnArrow(getNodeWithInvertedYCoord(props))) ) break case 'rxnPluses': structData.rxnPluses.forEach((props) => - struct.rxnPluses.add(new RxnPlus(props)) + struct.rxnPluses.add(new RxnPlus(getNodeWithInvertedYCoord(props))) ) break case 'simpleObjects': structData.simpleObjects.forEach((props) => - struct.simpleObjects.add(new SimpleObject(props)) + struct.simpleObjects.add( + new SimpleObject(getNodeWithInvertedYCoord(props)) + ) ) break case 'sgroups': @@ -1478,7 +1482,9 @@ const initStruct = (structName) => { }) break case 'texts': - structData.texts.forEach((props) => struct.texts.add(new Text(props))) + structData.texts.forEach((props) => + struct.texts.add(new Text(getNodeWithInvertedYCoord(props))) + ) break } }) diff --git a/packages/ketcher-core/src/domain/serializers/ket/fromKet/rxnToStruct.ts b/packages/ketcher-core/src/domain/serializers/ket/fromKet/rxnToStruct.ts index 431ef4c0ab..046e5e38e2 100644 --- a/packages/ketcher-core/src/domain/serializers/ket/fromKet/rxnToStruct.ts +++ b/packages/ketcher-core/src/domain/serializers/ket/fromKet/rxnToStruct.ts @@ -15,16 +15,17 @@ ***************************************************************************/ import { RxnArrow, RxnPlus, Struct } from 'domain/entities' +import { getNodeWithInvertedYCoord } from '../helpers' export function rxnToStruct(ketItem: any, struct: Struct): Struct { if (ketItem.type === 'arrow') { - struct.rxnArrows.add(new RxnArrow(ketItem.data)) + struct.rxnArrows.add(new RxnArrow(getNodeWithInvertedYCoord(ketItem.data))) } else { struct.rxnPluses.add( new RxnPlus({ pp: { x: ketItem.location[0], - y: ketItem.location[1], + y: -ketItem.location[1], z: ketItem.location[2] } }) diff --git a/packages/ketcher-core/src/domain/serializers/ket/fromKet/simpleObjectToStruct.ts b/packages/ketcher-core/src/domain/serializers/ket/fromKet/simpleObjectToStruct.ts index bd357fccc7..f4df9da69e 100644 --- a/packages/ketcher-core/src/domain/serializers/ket/fromKet/simpleObjectToStruct.ts +++ b/packages/ketcher-core/src/domain/serializers/ket/fromKet/simpleObjectToStruct.ts @@ -15,11 +15,12 @@ ***************************************************************************/ import { SimpleObject, SimpleObjectMode, Struct, Vec2 } from 'domain/entities' +import { getNodeWithInvertedYCoord } from '../helpers' export function simpleObjectToStruct(ketItem: any, struct: Struct): Struct { const object = ketItem.data.mode === 'circle' ? circleToEllipse(ketItem) : ketItem.data - struct.simpleObjects.add(new SimpleObject(object)) + struct.simpleObjects.add(new SimpleObject(getNodeWithInvertedYCoord(object))) return struct } diff --git a/packages/ketcher-core/src/domain/serializers/ket/fromKet/textToStruct.ts b/packages/ketcher-core/src/domain/serializers/ket/fromKet/textToStruct.ts index 85c03c530f..2326ac503b 100644 --- a/packages/ketcher-core/src/domain/serializers/ket/fromKet/textToStruct.ts +++ b/packages/ketcher-core/src/domain/serializers/ket/fromKet/textToStruct.ts @@ -15,9 +15,10 @@ ***************************************************************************/ import { Struct, Text } from 'domain/entities' +import { getNodeWithInvertedYCoord } from '../helpers' export function textToStruct(ketItem: any, struct: Struct) { - const object = ketItem.data + const object = getNodeWithInvertedYCoord(ketItem.data) struct.texts.add(new Text(object)) return struct diff --git a/packages/ketcher-core/src/domain/serializers/ket/helpers.ts b/packages/ketcher-core/src/domain/serializers/ket/helpers.ts new file mode 100644 index 0000000000..f4c585836e --- /dev/null +++ b/packages/ketcher-core/src/domain/serializers/ket/helpers.ts @@ -0,0 +1,28 @@ +/**************************************************************************** + * Copyright 2022 EPAM Systems + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +import { cloneDeepWith, cloneDeep } from 'lodash' + +const customizer = (value: any) => { + if (typeof value === 'object' && value.y) { + const clonedValue = cloneDeep(value) + clonedValue.y = -clonedValue.y + return clonedValue + } +} + +export const getNodeWithInvertedYCoord = (node: object) => + cloneDeepWith(node, customizer) diff --git a/packages/ketcher-core/src/domain/serializers/ket/toKet/rxnToKet.ts b/packages/ketcher-core/src/domain/serializers/ket/toKet/rxnToKet.ts index 89fc55d5ad..a488b6c330 100644 --- a/packages/ketcher-core/src/domain/serializers/ket/toKet/rxnToKet.ts +++ b/packages/ketcher-core/src/domain/serializers/ket/toKet/rxnToKet.ts @@ -14,10 +14,12 @@ * limitations under the License. ***************************************************************************/ +import { getNodeWithInvertedYCoord } from '../helpers' + export function arrowToKet(arrowNode) { return { type: 'arrow', - data: arrowNode.data + data: getNodeWithInvertedYCoord(arrowNode.data) } } @@ -25,7 +27,7 @@ export function plusToKet(plusNode) { const coord = plusNode.center return { type: 'plus', - location: [coord.x, coord.y, coord.z], + location: [coord.x, -coord.y, coord.z], prop: plusNode.data } } diff --git a/packages/ketcher-core/src/domain/serializers/ket/toKet/simpleObjectToKet.ts b/packages/ketcher-core/src/domain/serializers/ket/toKet/simpleObjectToKet.ts index d55d4c44dd..060328865b 100644 --- a/packages/ketcher-core/src/domain/serializers/ket/toKet/simpleObjectToKet.ts +++ b/packages/ketcher-core/src/domain/serializers/ket/toKet/simpleObjectToKet.ts @@ -14,9 +14,11 @@ * limitations under the License. ***************************************************************************/ +import { getNodeWithInvertedYCoord } from '../helpers' + export function simpleObjectToKet(simpleObjectNode) { return { type: 'simpleObject', - data: simpleObjectNode.data + data: getNodeWithInvertedYCoord(simpleObjectNode.data) } } diff --git a/packages/ketcher-core/src/domain/serializers/ket/toKet/textToKet.ts b/packages/ketcher-core/src/domain/serializers/ket/toKet/textToKet.ts index 38db56d487..fa410f8f6a 100644 --- a/packages/ketcher-core/src/domain/serializers/ket/toKet/textToKet.ts +++ b/packages/ketcher-core/src/domain/serializers/ket/toKet/textToKet.ts @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. ***************************************************************************/ +import { getNodeWithInvertedYCoord } from '../helpers' export function textToKet(textNode) { return { type: 'text', - data: textNode.data + data: getNodeWithInvertedYCoord(textNode.data) } } diff --git a/packages/ketcher-standalone/package.json b/packages/ketcher-standalone/package.json index c4b40b5178..d7e80c7163 100644 --- a/packages/ketcher-standalone/package.json +++ b/packages/ketcher-standalone/package.json @@ -39,7 +39,7 @@ }, "dependencies": { "@babel/runtime": "^7.17.9", - "indigo-ketcher": "1.6.6-0", + "indigo-ketcher": "1.7.0-alpha-0", "ketcher-core": "workspace:*" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 724a956a38..277e8421c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9276,10 +9276,10 @@ __metadata: languageName: node linkType: hard -"indigo-ketcher@npm:1.6.6-0": - version: 1.6.6-0 - resolution: "indigo-ketcher@npm:1.6.6-0" - checksum: 7d8008b4f6fe9d26d2a7ce8f854483a8510180118d822a769c8bf30a84abea2683a2a97686df7c271e41f1d6bb648d3947612fdf16a9c9417e76138c82db3e0b +"indigo-ketcher@npm:1.7.0-alpha-0": + version: 1.7.0-alpha-0 + resolution: "indigo-ketcher@npm:1.7.0-alpha-0" + checksum: 9f4baee6cff7be91c247634d5c910fe5676d25d09a4cf78124cd74c86e687c7d7e619d9d62770d3df66ab8a7833206ab5fd5d4b806eb380cefeb7c36eafaa9c1 languageName: node linkType: hard @@ -11460,7 +11460,7 @@ __metadata: cross-env: ^7.0.3 eslint: ^8.4.1 eslint-plugin-jest: ^25.3.0 - indigo-ketcher: 1.6.6-0 + indigo-ketcher: 1.7.0-alpha-0 jest: 26.6.0 ketcher-core: "workspace:*" npm-run-all: ^4.1.5