Skip to content

Commit

Permalink
Merge branch 'master' into #1899-add-right-click-menu-for-atoms
Browse files Browse the repository at this point in the history
  • Loading branch information
yuleicul committed Jan 3, 2023
2 parents 5ec5d12 + 06be47a commit 19ace0d
Show file tree
Hide file tree
Showing 40 changed files with 734 additions and 289 deletions.
7 changes: 7 additions & 0 deletions packages/ketcher-core/src/application/actions/action.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
* limitations under the License.
***************************************************************************/

// import { Operation } from "application/operations"
// import { ReStruct } from "application/render"

export interface Action {
perform: () => void
// operations: Array<Operation>
// mergeWith(action: Action): Action
// addOp(operation: Operation, restruct?: ReStruct): Operation
// isDummy(restruct?: ReStruct): boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ export interface Editor {
setOptions: (opts: string) => any
zoom: (value?: any) => any
structSelected: () => Struct
// update: (action: Action | true, ignoreHistory?: boolean) => void
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ const formatProperties: FormatPropertiesMap = {
ChemicalMimeType.CDX,
['.cdx'],
true
),
unknown: new SupportedFormatProperties(
'Unknown',
ChemicalMimeType.UNKNOWN,
['.'],
true
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class FormatterFactory {
case SupportedFormat.smarts:
case SupportedFormat.cdxml:
case SupportedFormat.cdx:
case SupportedFormat.unknown:
default:
formatter = new ServerFormatter(
this.#structService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export function identifyStructFormat(
return SupportedFormat.rxn
}

if (sanitizedString.indexOf('V2000') !== -1) {
return SupportedFormat.mol
}

if (sanitizedString.indexOf('V3000') !== -1) {
return SupportedFormat.molV3000
}
Expand All @@ -55,12 +59,16 @@ export function identifyStructFormat(
return SupportedFormat.cml
}

const clearStr = sanitizedString.replace(/\s/g, '')
const anyLetterAnyDigitContainsSlashesEndsWithEqualSign =
/^[a-zA-Z0-9+/]*={0,2}$/
const clearStr = sanitizedString
.replace(/\s/g, '')
.replace(/(\\r)|(\\n)/g, '')
const isBase64String =
/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/
const cdxHeader = 'VjCD0100'
if (
anyLetterAnyDigitContainsSlashesEndsWithEqualSign.test(clearStr) &&
clearStr.length % 4 === 0
clearStr.length % 4 === 0 &&
isBase64String.test(clearStr) &&
window.atob(clearStr).startsWith(cdxHeader)
) {
return SupportedFormat.cdx
}
Expand All @@ -69,17 +77,14 @@ export function identifyStructFormat(
return SupportedFormat.inChI
}

if (
sanitizedString.indexOf('\n') === -1 &&
sanitizedString === sanitizedString.toUpperCase()
) {
if (sanitizedString.indexOf('\n') === -1) {
// TODO: smiles regexp
return SupportedFormat.smiles
}

if (sanitizedString.indexOf('<CDXML') !== -1) {
return SupportedFormat.cdxml
}
// Molfile by default as Indigo does
return SupportedFormat.mol

return SupportedFormat.unknown
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export enum SupportedFormat {
cml = 'cml',
ket = 'ket',
cdxml = 'cdxml',
cdx = 'cdx'
cdx = 'cdx',
unknown = 'unknown'
}

export type FormatterFactoryOptions = Partial<
Expand Down
1 change: 1 addition & 0 deletions packages/ketcher-core/src/application/operations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from './rxnPlus'
export * from './sgroup'
export * from './simpleObject'
export * from './text'
export * from './baseOperation'
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
***************************************************************************/

import { ReStruct } from 'application/render'
import { Struct } from 'domain/entities'

export type OperationType =
Expand Down Expand Up @@ -70,8 +71,13 @@ export type OperationType =
export interface Operation {
readonly type: OperationType
readonly priority: number
readonly _inverted: OperationType | undefined
data: any
// eslint-disable-next-line no-use-before-define
perform: (struct: Struct) => PerformOperationResult
invert(): Operation
isDummy(_restruct: ReStruct): boolean
execute(_restruct: ReStruct): void
}

export type PerformOperationResult = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,14 @@ class ReStruct {
item.selected = sGroupAtoms.length > 0 && sGroupAtoms[0].selected
}

const selected = selection?.[map]
let selected = selection?.[map]
? selection[map].indexOf(id) > -1
: item.selected

if (selection === null) {
selected = false
}

this.showItemSelection(item, selected)
})
}
Expand Down
11 changes: 8 additions & 3 deletions packages/ketcher-core/src/domain/entities/functionalGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ export class FunctionalGroup {
static getFunctionalGroupByName(searchName: string): Struct | null {
const provider = FunctionalGroupsProvider.getInstance()
const functionalGroups = provider.getFunctionalGroupsList()
const foundGroup = functionalGroups.find(({ name, abbreviation }) => {
return name === searchName || abbreviation === searchName
})

let foundGroup
if (searchName) {
foundGroup = functionalGroups.find(({ name, abbreviation }) => {
return name === searchName || abbreviation === searchName
})
}

return foundGroup || null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export enum ChemicalMimeType {
CDX = 'chemical/x-cdx',
CDXML = 'chemical/x-cdxml',
CML = 'chemical/x-cml',
KET = 'chemical/x-indigo-ket'
KET = 'chemical/x-indigo-ket',
UNKNOWN = 'chemical/x-unknown'
}

export interface WithStruct {
Expand Down
1 change: 1 addition & 0 deletions packages/ketcher-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-typescript2": "^0.31.1",
"rollup-plugin-visualizer": "^5.5.2",
"stylelint": "13.13.1",
Expand Down
6 changes: 5 additions & 1 deletion packages/ketcher-react/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import strip from '@rollup/plugin-strip'
import svgr from '@svgr/rollup'
import typescript from 'rollup-plugin-typescript2'
import { license } from '../../license.ts'
import { string } from 'rollup-plugin-string'

const mode = {
PRODUCTION: 'production',
Expand Down Expand Up @@ -98,7 +99,10 @@ const config = {
comments: 'none',
include: includePattern
}),
...(isProduction ? [strip({ include: includePattern })] : [])
...(isProduction ? [strip({ include: includePattern })] : []),
string({
include: '**/*.sdf'
})
]
}

Expand Down
6 changes: 5 additions & 1 deletion packages/ketcher-react/src/script/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class Editor implements KetcherEditor {
}
}

update(action: Action | true, ignoreHistory?) {
update(action: Action | true, ignoreHistory?: boolean) {
if (action === true) {
this.render.update(true) // force
} else {
Expand Down Expand Up @@ -606,6 +606,10 @@ function domEventSetup(editor: Editor, clientArea) {
editor.lastEvent = event
if (EditorTool && eventName in EditorTool) {
EditorTool[eventName](event)
return true
}
if (eventName === 'mouseup') {
editor.selection(null)
}
return true
}, -1)
Expand Down
2 changes: 1 addition & 1 deletion packages/ketcher-react/src/script/editor/tool/bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class BondTool {

this.editor.update(bondAddition[0])
} else if (dragCtx.item.map === 'atoms') {
// when does it hapend?
// click on atom
this.editor.update(
fromBondAddition(
rnd.ctab,
Expand Down
5 changes: 3 additions & 2 deletions packages/ketcher-react/src/script/editor/tool/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {

import LassoHelper from './helper/lasso'
import { atomLongtapEvent } from './atom'
import { sgroupDialog } from './sgroup'
import SGroupTool from './sgroup'
import utils from '../shared/utils'
import { xor } from 'lodash/fp'
import { Editor } from '../Editor'
Expand Down Expand Up @@ -193,6 +193,7 @@ class SelectTool {
if (event.shiftKey) {
this.editor.selection(selMerge(sel, selection, true))
} else {
this.editor.selection(null)
this.editor.selection(isSelected(selection, ci) ? selection : sel)
}
return true
Expand Down Expand Up @@ -535,7 +536,7 @@ class SelectTool {
ci.map === 'sgroupData'
) {
editor.selection(closestToSel(ci))
sgroupDialog(editor, ci.id, null)
SGroupTool.sgroupDialog(editor, ci.id, null)
} else if (ci.map === 'texts') {
editor.selection(closestToSel(ci))
const text = molecule.texts.get(ci.id)
Expand Down
Loading

0 comments on commit 19ace0d

Please sign in to comment.