Skip to content

Commit

Permalink
Merge branch 'master' into #2043-thumbnail-images-are-not-readable-in…
Browse files Browse the repository at this point in the history
…-template-dialog
  • Loading branch information
porcelain11 committed Jan 10, 2023
2 parents ae70185 + 60d9679 commit d183f47
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 28 deletions.
12 changes: 6 additions & 6 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
"version": "1.0.0",
"private": true,
"scripts": {
"start:standalone": "cross-env MODE=standalone ENABLE_POLYMER_EDITOR=false react-app-rewired start",
"start:remote": "cross-env MODE=remote ENABLE_POLYMER_EDITOR=false react-app-rewired start",
"start:standalone": "cross-env MODE=standalone react-app-rewired start",
"start:remote": "cross-env MODE=remote react-app-rewired start",
"clean:build": "shx rm -rf build",
"delete:dist": "shx rm -rf dist/$MODE",
"init:dist": "shx mkdir -p dist/$MODE",
"copy:build": "shx cp -r build/. dist/$MODE",
"prebuild": "run-s delete:dist init:dist",
"postbuild": "run-s copy:build clean:build",
"build:remote": "cross-env MODE=remote ENABLE_POLYMER_EDITOR=false run-s prebuild build:react postbuild",
"build:standalone": "cross-env MODE=standalone ENABLE_POLYMER_EDITOR=false run-s prebuild build:react postbuild",
"build:remote": "cross-env MODE=remote run-s prebuild build:react postbuild",
"build:standalone": "cross-env MODE=standalone run-s prebuild build:react postbuild",
"build:react": "react-app-rewired build",
"build:react:analyze": "react-app-rewired build --analyze",
"build": "run-s build:standalone build:remote",
"build:standalone:analyze": "cross-env MODE=standalone ENABLE_POLYMER_EDITOR=false run-s prebuild build:react:analyze postbuild",
"build:remote:analyze": "cross-env MODE=remote ENABLE_POLYMER_EDITOR=false run-s prebuild build:react:analyze postbuild",
"build:standalone:analyze": "cross-env MODE=standalone run-s prebuild build:react:analyze postbuild",
"build:remote:analyze": "cross-env MODE=remote run-s prebuild build:react:analyze postbuild",
"test": "run-s test:prettier test:stylelint test:eslint test:unit",
"test:eslint": "eslint . --ext .ts,.js,.jsx,.tsx",
"test:unit": "react-app-rewired test --passWithNoTests",
Expand Down
29 changes: 25 additions & 4 deletions packages/ketcher-core/src/application/render/restruct/resgroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,34 @@ class ReSGroup extends ReObject {
return set
}

getTextHighlightDimensions(render) {
const sGroupItem = this.item
const [firstAtomId] = sGroupItem.atoms
const sGroupAtom = render.ctab.atoms.get(firstAtomId)
const [sGroupAtomSVGElement] = sGroupAtom.visel.paths
const atomTextBoundingBox = sGroupAtomSVGElement.getBBox()
const padding = render.options.fontsz / 2
const { x, y, x2, y2 } = atomTextBoundingBox
const startX = x - render.options.offset.x - padding
const startY = y - render.options.offset.y - padding
const width = x2 - x + padding * 2
const height = y2 - y + padding * 2

return { startX, startY, width, height }
}

makeSelectionPlate(restruct, paper, options) {
const sgroup = this.item
const { startX, startY, size } = getHighlighPathInfo(sgroup, options)
const functionalGroups = restruct.molecule.functionalGroups
if (
FunctionalGroup.isContractedFunctionalGroup(sgroup.id, functionalGroups)
) {
return paper.rect(startX, startY, size, size).attr(options.selectionStyle)
const { startX, startY, width, height } = this.getTextHighlightDimensions(
this.render
)
return paper
.rect(startX, startY, width, height)
.attr(options.selectionStyle)
}
}

Expand All @@ -149,9 +169,10 @@ class ReSGroup extends ReObject {
functionalGroups
)
) {
const { startX, startY, size } = getHighlighPathInfo(sGroupItem, options)
const { startX, startY, width, height } =
this.getTextHighlightDimensions(render)
sGroupItem.hovering = paper
.rect(startX, startY, size, size)
.rect(startX, startY, width, height)
.attr(options.hoverStyle)
} else {
sGroupItem.hovering = paper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ export class Molfile {
this.writeWhiteSpace()
this.writePadded(labelList[k], 3)
}
this.writeWhiteSpace()
this.writeCR()
}
}
Expand Down
54 changes: 46 additions & 8 deletions packages/ketcher-react/src/script/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Editor implements KetcherEditor {
errorHandler: ((message: string) => void) | null
highlights: Highlighter
hoverIcon: any
lastCursorPosition: { x: number; y: number }
event: {
message: Subscription
elementEdit: PipelineSubscription
Expand Down Expand Up @@ -155,10 +156,11 @@ class Editor implements KetcherEditor {
this.renderAndRecoordinateStruct.bind(this)
this.setOptions = this.setOptions.bind(this)

this.hoverIcon = this.render.paper
.text(0, 0, '')
.attr('font-size', options.fontsz)
.attr('opacity', HOVER_ICON_OPACITY)
this.lastCursorPosition = {
x: 0,
y: 0
}
this.createHoverIcon()

this.event = {
message: new Subscription(),
Expand Down Expand Up @@ -224,6 +226,24 @@ class Editor implements KetcherEditor {
/* eslint-enable no-underscore-dangle */
}

updateHoverIconPosition() {
const { x, y } = this.lastCursorPosition
const { height, width } = this.hoverIcon.getBBox()
this.hoverIcon.attr({
x: x - width / 2,
y: y - height / 2
})
}

createHoverIcon() {
this.hoverIcon = this.render.paper
.text(0, 0, '')
.attr('font-size', this.options().fontsz)
.attr('opacity', HOVER_ICON_OPACITY)

this.updateHoverIconPosition()
}

clear() {
this.struct(undefined)
}
Expand All @@ -245,7 +265,10 @@ class Editor implements KetcherEditor {
this.selection(null)
const struct = value || new Struct()

return this.renderAndRecoordinateStruct(struct)
const molecule = this.renderAndRecoordinateStruct(struct)

this.createHoverIcon()
return molecule
}

// this is used by API addFragment method
Expand Down Expand Up @@ -574,6 +597,22 @@ function isMouseRight(event) {
)
}

function resetSelectionOnCanvasClick(editor: Editor, eventName: string) {
if (eventName === 'mouseup') {
editor.selection(null)
}
}

function updateLastCursorPosition(editor: Editor, event) {
const events = ['mousemove', 'click', 'mousedown', 'mouseup', 'mouseover']
if (events.includes(event.type)) {
editor.lastCursorPosition = {
x: event.layerX,
y: event.layerY
}
}
}

function domEventSetup(editor: Editor, clientArea) {
// TODO: addEventListener('resize', ...);
;[
Expand All @@ -590,6 +629,7 @@ function domEventSetup(editor: Editor, clientArea) {
clientArea.addEventListener(eventName, subs.dispatch.bind(subs))

subs.add((event) => {
updateLastCursorPosition(editor, event)
if (eventName !== 'mouseup' && eventName !== 'mouseleave') {
// to complete drag actions
if (
Expand All @@ -608,9 +648,7 @@ function domEventSetup(editor: Editor, clientArea) {
EditorTool[eventName](event)
return true
}
if (eventName === 'mouseup') {
editor.selection(null)
}
resetSelectionOnCanvasClick(editor, eventName)
return true
}, -1)
})
Expand Down
2 changes: 2 additions & 0 deletions packages/ketcher-react/src/script/editor/tool/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AtomTool {
.show()
.attr('text', `${atomProps.label}`)
.attr('fill', `${ElementColor[atomProps.label]}`)
this.editor.updateHoverIconPosition()

if (editor.selection()) {
if (editor.selection()?.atoms) {
Expand Down Expand Up @@ -140,6 +141,7 @@ class AtomTool {

mouseover() {
this.editor.hoverIcon.show()
this.editor.updateHoverIconPosition()
}

mousemove(event) {
Expand Down
12 changes: 6 additions & 6 deletions packages/ketcher-react/src/templates/fg.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ PO3H2
Ketcher 11161713142D 1 1.00000 0.00000 0

4 3 0 0 1 0 0 0 0 0999 V2000
-1.2500 0.8500 0.0000 P 0 0 0 0 0 5 0 0 0 0 0 0
-1.2500 0.8500 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0
-1.2500 2.3500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
-1.2500 -0.6500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
0.2500 0.8500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
Expand Down Expand Up @@ -1251,7 +1251,7 @@ Ketcher 11161713142D 1 1.00000 0.00000 0

5 4 0 0 1 0 0 0 0 0999 V2000
-2.7500 0.8500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
-1.2500 0.8500 0.0000 P 0 0 0 0 0 5 0 0 0 0 0 0
-1.2500 0.8500 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0
-1.2500 2.3500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
-1.2500 -0.6500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
0.2500 0.8500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
Expand Down Expand Up @@ -1402,7 +1402,7 @@ SO2H
Ketcher 11161713142D 1 1.00000 0.00000 0

3 2 0 0 1 0 0 0 0 0999 V2000
-1.2500 0.8500 0.0000 S 0 0 0 0 0 5 0 0 0 0 0 0
-1.2500 0.8500 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0
-1.2500 2.3500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
-1.2500 -0.6500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
1 2 2 0 0 0 0
Expand Down Expand Up @@ -1453,7 +1453,7 @@ SO3H
Ketcher 11161713142D 1 1.00000 0.00000 0

4 3 0 0 1 0 0 0 0 0999 V2000
-1.2500 0.8500 0.0000 S 0 0 0 0 0 6 0 0 0 0 0 0
-1.2500 0.8500 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0
-1.2500 2.3500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
-1.2500 -0.6500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
0.2500 0.8500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
Expand Down Expand Up @@ -1509,7 +1509,7 @@ Ketcher 11161713142D 1 1.00000 0.00000 0

5 4 0 0 1 0 0 0 0 0999 V2000
-2.7500 0.8500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
-1.2500 0.8500 0.0000 S 0 0 0 0 0 6 0 0 0 0 0 0
-1.2500 0.8500 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0
-1.2500 2.3500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
-1.2500 -0.6500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
0.2500 0.8500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
Expand Down Expand Up @@ -1763,7 +1763,7 @@ Tos
Ketcher 11161713142D 1 1.00000 0.00000 0

10 10 0 0 1 0 0 0 0 0999 V2000
0.0000 0.0000 0.0000 S 0 0 0 0 0 6 0 0 0 0 0 0
0.0000 0.0000 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0
1.5000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 1.5000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 -1.5000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
Expand Down
8 changes: 4 additions & 4 deletions packages/ketcher-react/src/templates/salts-and-solvents.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ methane sulphonic acid
-INDIGO-11302219142D

5 4 0 0 0 0 0 0 0 0999 V2000
0.5143 0.5143 0.0000 S 0 0 0 0 0 6 0 0 0 0 0 0
0.5143 0.5143 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0
0.5143 2.0143 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
0.5143 -0.9857 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
2.0143 0.5143 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
Expand Down Expand Up @@ -1056,7 +1056,7 @@ dimethyl sulfoxide
-INDIGO-11302219142D

4 3 0 0 0 0 0 0 0 0999 V2000
1.5000 0.0000 0.0000 S 0 0 0 0 0 4 0 0 0 0 0 0
1.5000 0.0000 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0
0.2010 -0.7500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.7990 -0.7500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.5000 1.5000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
Expand Down Expand Up @@ -1233,7 +1233,7 @@ sulfolane
-INDIGO-11302219142D

7 7 0 0 0 0 0 0 0 0999 V2000
0.7500 2.3100 0.0000 S 0 0 0 0 0 6 0 0 0 0 0 0
0.7500 2.3100 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0
-0.4600 1.4300 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.9600 1.4300 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
Expand Down Expand Up @@ -3921,7 +3921,7 @@ hexamethylphosphoramide
2.3174 -0.9012 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3.6235 -1.9903 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
4.8900 -0.9145 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3.5935 -3.2519 0.0000 P 0 0 0 0 0 5 0 0 0 0 0 0
3.5935 -3.2519 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0
3.5935 -4.7619 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
5.0831 -3.2205 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
6.0654 -4.1562 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
Expand Down

0 comments on commit d183f47

Please sign in to comment.