ketcher-react 2.4.1 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
9
9
  import _regeneratorRuntime from '@babel/runtime/regenerator';
10
10
  import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
11
11
  import _createClass from '@babel/runtime/helpers/createClass';
12
- import { KetSerializer, MolSerializer, Ketcher, FormatterFactory, StereLabelStyleType, StereoColoringType, Bond as Bond$2, Elements, AtomList, StereoLabel, RxnArrowMode, SimpleObjectMode, SGroup, Pile, getStereoAtomsMap, identifyStructFormat, ChemicalMimeType, SdfSerializer, FunctionalGroupsProvider, ElementColor, formatProperties, Vec2, FunctionalGroup, Fragment as Fragment$1, OperationType, fromAtomsAttrs, fracAngle, Atom as Atom$2, fromAtomAddition, Action, fromSgroupDeletion, fromFragmentDeletion, fromBondAddition, fromBondsAttrs, bondChangingAction, fromChain, getItemsToFuse, getHoverToFuse, fromItemsFuse, findStereoAtoms, fromStereoFlagUpdate, Scale, checkOverlapping, fromSeveralSgroupAddition, SgContexts, fromSgroupAction, fromSimpleObjectResizing, fromArrowResizing, fromMultipleMove, fromTextDeletion, fromTextUpdating, fromOneAtomDeletion, fromOneBondDeletion, fromArrowDeletion, fromPlusDeletion, fromSimpleObjectDeletion, fromPaste, RGroup as RGroup$2, fromRGroupFragment, fromUpdateIfThen, fromRGroupAttrs, fromArrowAddition, fromPlusAddition, fromRotate, fromFlip, fromBondAlign, fromSimpleObjectAddition, fromTemplateOnBondAction, fromTemplateOnCanvas, fromTemplateOnAtom, fromTextCreation, Struct, fromNewCanvas, Render, fromDescriptorsAlign, setExpandSGroup, getPropertiesByFormat, StereoFlag, Generics, TextCommand } from 'ketcher-core';
12
+ import { KetSerializer, MolSerializer, Ketcher, FormatterFactory, StereLabelStyleType, StereoColoringType, Bond as Bond$2, Elements, AtomList, StereoLabel, RxnArrowMode, SimpleObjectMode, SGroup, Pile, getStereoAtomsMap, identifyStructFormat, ChemicalMimeType, SdfSerializer, FunctionalGroupsProvider, ElementColor, formatProperties, Vec2, FunctionalGroup, Fragment as Fragment$1, OperationType, fromAtomsAttrs, fracAngle, Atom as Atom$2, fromAtomAddition, Action, fromSgroupDeletion, fromFragmentDeletion, fromBondAddition, fromBondsAttrs, bondChangingAction, fromChain, getItemsToFuse, getHoverToFuse, fromItemsFuse, findStereoAtoms, fromStereoFlagUpdate, Scale, checkOverlapping, fromSeveralSgroupAddition, SgContexts, fromSgroupAction, fromSimpleObjectResizing, fromArrowResizing, fromMultipleMove, fromTextDeletion, fromTextUpdating, fromOneAtomDeletion, fromOneBondDeletion, fromArrowDeletion, fromPlusDeletion, fromSimpleObjectDeletion, fromPaste, RGroup as RGroup$2, fromRGroupFragment, fromUpdateIfThen, fromRGroupAttrs, fromArrowAddition, fromPlusAddition, fromRotate, fromFlip, fromBondAlign, fromSimpleObjectAddition, fromTemplateOnBondAction, fromTemplateOnCanvas, fromTemplateOnAtom, fromTextCreation, fromHighlightCreate, fromHighlightClear, Struct, fromNewCanvas, Render, fromDescriptorsAlign, setExpandSGroup, getPropertiesByFormat, StereoFlag, Generics, TextCommand } from 'ketcher-core';
13
13
  import * as React from 'react';
14
14
  import React__default, { createRef, Component, useState, useEffect, useRef, useMemo, createElement, forwardRef, useLayoutEffect, useCallback } from 'react';
15
15
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
@@ -10874,6 +10874,95 @@ var tools = {
10874
10874
  text: TextToolWrapper
10875
10875
  };
10876
10876
 
10877
+ var Highlighter = function () {
10878
+ function Highlighter(editor) {
10879
+ _classCallCheck(this, Highlighter);
10880
+ _defineProperty(this, "editor", void 0);
10881
+ this.editor = editor;
10882
+ }
10883
+ _createClass(Highlighter, [{
10884
+ key: "getAll",
10885
+ value: function getAll() {
10886
+ var highlightsMap = this.editor.render.ctab.molecule.highlights;
10887
+ var highlightsArray = _toConsumableArray(highlightsMap).map(function (_ref) {
10888
+ var _ref2 = _slicedToArray(_ref, 2),
10889
+ id = _ref2[0],
10890
+ highlight = _ref2[1];
10891
+ return {
10892
+ id: id,
10893
+ highlight: highlight
10894
+ };
10895
+ });
10896
+ return highlightsArray;
10897
+ }
10898
+ }, {
10899
+ key: "create",
10900
+ value: function create() {
10901
+ var _this = this;
10902
+ var createdHighlights = [];
10903
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10904
+ args[_key] = arguments[_key];
10905
+ }
10906
+ args.forEach(function (arg) {
10907
+ var atoms = arg.atoms,
10908
+ bonds = arg.bonds,
10909
+ color = arg.color;
10910
+ if (typeof color !== 'string') {
10911
+ return;
10912
+ }
10913
+ if (!atoms && !bonds) {
10914
+ return;
10915
+ }
10916
+ var restruct = _this.editor.render.ctab;
10917
+ var _getValidInputOnly = getValidInputOnly(restruct.molecule, atoms, bonds),
10918
+ validAtoms = _getValidInputOnly.validAtoms,
10919
+ validBonds = _getValidInputOnly.validBonds;
10920
+ if (validAtoms.length === 0 && validBonds.length === 0) {
10921
+ return;
10922
+ }
10923
+ createdHighlights.push({
10924
+ atoms: validAtoms,
10925
+ bonds: validBonds,
10926
+ color: color
10927
+ });
10928
+ });
10929
+ var action = fromHighlightCreate(this.editor.render.ctab, createdHighlights);
10930
+ this.editor.update(action);
10931
+ }
10932
+ }, {
10933
+ key: "clear",
10934
+ value: function clear() {
10935
+ var action = fromHighlightClear(this.editor.render.ctab);
10936
+ this.editor.update(action);
10937
+ }
10938
+ }]);
10939
+ return Highlighter;
10940
+ }();
10941
+ function getValidInputOnly(struct, atoms, bonds) {
10942
+ if (!Array.isArray(atoms)) {
10943
+ atoms = [];
10944
+ }
10945
+ if (!Array.isArray(bonds)) {
10946
+ bonds = [];
10947
+ }
10948
+ var structAtoms = struct.atoms,
10949
+ structBonds = struct.bonds;
10950
+ if (atoms.length > 0) {
10951
+ atoms = atoms.filter(function (aid) {
10952
+ return structAtoms.has(aid);
10953
+ });
10954
+ }
10955
+ if (bonds.length > 0) {
10956
+ bonds = bonds.filter(function (bid) {
10957
+ return structBonds.has(bid);
10958
+ });
10959
+ }
10960
+ return {
10961
+ validAtoms: atoms,
10962
+ validBonds: bonds
10963
+ };
10964
+ }
10965
+
10877
10966
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
10878
10967
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
10879
10968
  var SCALE = 40;
@@ -10909,6 +10998,7 @@ var Editor$2 = function () {
10909
10998
  _defineProperty(this, "historyStack", void 0);
10910
10999
  _defineProperty(this, "historyPtr", void 0);
10911
11000
  _defineProperty(this, "errorHandler", void 0);
11001
+ _defineProperty(this, "highlights", void 0);
10912
11002
  _defineProperty(this, "event", void 0);
10913
11003
  _defineProperty(this, "lastEvent", void 0);
10914
11004
  this.render = new Render(clientArea, Object.assign({
@@ -10919,6 +11009,7 @@ var Editor$2 = function () {
10919
11009
  this.historyStack = [];
10920
11010
  this.historyPtr = 0;
10921
11011
  this.errorHandler = null;
11012
+ this.highlights = new Highlighter(this);
10922
11013
  this.event = {
10923
11014
  message: new Subscription(),
10924
11015
  elementEdit: new PipelineSubscription(),
@@ -11067,48 +11158,10 @@ var Editor$2 = function () {
11067
11158
  value: function hover(ci, newTool) {
11068
11159
  var tool = newTool || this._tool;
11069
11160
  if ('ci' in tool && (!ci || tool.ci.map !== ci.map || tool.ci.id !== ci.id)) {
11070
- this.highlight(tool.ci, false);
11161
+ setHover(tool.ci, false, this.render);
11071
11162
  delete tool.ci;
11072
11163
  }
11073
- if (ci && this.highlight(ci, true)) tool.ci = ci;
11074
- }
11075
- }, {
11076
- key: "highlight",
11077
- value: function highlight(ci, visible) {
11078
- if (highlightTargets.indexOf(ci.map) === -1) {
11079
- return false;
11080
- }
11081
- var render = this.render;
11082
- var item = null;
11083
- if (ci.map === 'merge') {
11084
- Object.keys(ci.items).forEach(function (mp) {
11085
- ci.items[mp].forEach(function (dstId) {
11086
- item = render.ctab[mp].get(dstId);
11087
- if (item) {
11088
- item.setHighlight(visible, render);
11089
- }
11090
- });
11091
- });
11092
- return true;
11093
- }
11094
- if (ci.map === 'functionalGroups') ci.map = 'sgroups';
11095
- item = render.ctab[ci.map].get(ci.id);
11096
- if (!item) {
11097
- return true;
11098
- }
11099
- if (ci.map === 'sgroups' && item.item.type === 'DAT' || ci.map === 'sgroupData') {
11100
- var item1 = render.ctab.sgroups.get(ci.id);
11101
- if (item1) {
11102
- item1.setHighlight(visible, render);
11103
- }
11104
- var item2 = render.ctab.sgroupData.get(ci.id);
11105
- if (item2) {
11106
- item2.setHighlight(visible, render);
11107
- }
11108
- } else {
11109
- item.setHighlight(visible, render);
11110
- }
11111
- return true;
11164
+ if (ci && setHover(ci, true, this.render)) tool.ci = ci;
11112
11165
  }
11113
11166
  }, {
11114
11167
  key: "update",
@@ -11300,6 +11353,41 @@ function getStructCenter(ReStruct, selection) {
11300
11353
  var bb = ReStruct.getVBoxObj(selection || {});
11301
11354
  return Vec2.lc2(bb.p0, 0.5, bb.p1, 0.5);
11302
11355
  }
11356
+ function setHover(ci, visible, render) {
11357
+ if (highlightTargets.indexOf(ci.map) === -1) {
11358
+ return false;
11359
+ }
11360
+ var item = null;
11361
+ if (ci.map === 'merge') {
11362
+ Object.keys(ci.items).forEach(function (mp) {
11363
+ ci.items[mp].forEach(function (dstId) {
11364
+ item = render.ctab[mp].get(dstId);
11365
+ if (item) {
11366
+ item.setHover(visible, render);
11367
+ }
11368
+ });
11369
+ });
11370
+ return true;
11371
+ }
11372
+ if (ci.map === 'functionalGroups') ci.map = 'sgroups';
11373
+ item = render.ctab[ci.map].get(ci.id);
11374
+ if (!item) {
11375
+ return true;
11376
+ }
11377
+ if (ci.map === 'sgroups' && item.item.type === 'DAT' || ci.map === 'sgroupData') {
11378
+ var item1 = render.ctab.sgroups.get(ci.id);
11379
+ if (item1) {
11380
+ item1.setHover(visible, render);
11381
+ }
11382
+ var item2 = render.ctab.sgroupData.get(ci.id);
11383
+ if (item2) {
11384
+ item2.setHover(visible, render);
11385
+ }
11386
+ } else {
11387
+ item.setHover(visible, render);
11388
+ }
11389
+ return true;
11390
+ }
11303
11391
 
11304
11392
  var classes$E = {"dialog_body":"StructEditor-module_dialog_body__1WUMs","scrollbar":"StructEditor-module_scrollbar__2RsBC","spinnerOverlay":"StructEditor-module_spinnerOverlay__Q8idX","canvas":"StructEditor-module_canvas__3PrVC","measureLog":"StructEditor-module_measureLog__3FnNR","visible":"StructEditor-module_visible__l4qPY","intermediateCanvas":"StructEditor-module_intermediateCanvas__jP3l0"};
11305
11393
 
@@ -15875,11 +15963,11 @@ var EDITOR_STYLES = {
15875
15963
  fill: '#47b3ec',
15876
15964
  stroke: 'none'
15877
15965
  },
15878
- highlightStyle: {
15966
+ hoverStyle: {
15879
15967
  stroke: '#1a7090',
15880
15968
  'stroke-width': 1.2
15881
15969
  },
15882
- highlightStyleSimpleObject: {
15970
+ hoverStyleSimpleObject: {
15883
15971
  'stroke-opacity': 0.3
15884
15972
  }
15885
15973
  };
@@ -16774,8 +16862,8 @@ var KetcherBuilder = function () {
16774
16862
  initApp(element, staticResourcesUrl, {
16775
16863
  buttons: buttons || {},
16776
16864
  errorHandler: errorHandler || null,
16777
- version: "2.4.1" ,
16778
- buildDate: "2022-01-13T18:04:07" ,
16865
+ version: "2.4.2" ,
16866
+ buildDate: "2022-02-21T15:06:53" ,
16779
16867
  buildNumber: ''
16780
16868
  }, structService, resolve);
16781
16869
  });