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.
package/dist/index.js CHANGED
@@ -10925,6 +10925,95 @@ var tools = {
10925
10925
  text: TextToolWrapper
10926
10926
  };
10927
10927
 
10928
+ var Highlighter = function () {
10929
+ function Highlighter(editor) {
10930
+ _classCallCheck__default["default"](this, Highlighter);
10931
+ _defineProperty__default["default"](this, "editor", void 0);
10932
+ this.editor = editor;
10933
+ }
10934
+ _createClass__default["default"](Highlighter, [{
10935
+ key: "getAll",
10936
+ value: function getAll() {
10937
+ var highlightsMap = this.editor.render.ctab.molecule.highlights;
10938
+ var highlightsArray = _toConsumableArray__default["default"](highlightsMap).map(function (_ref) {
10939
+ var _ref2 = _slicedToArray__default["default"](_ref, 2),
10940
+ id = _ref2[0],
10941
+ highlight = _ref2[1];
10942
+ return {
10943
+ id: id,
10944
+ highlight: highlight
10945
+ };
10946
+ });
10947
+ return highlightsArray;
10948
+ }
10949
+ }, {
10950
+ key: "create",
10951
+ value: function create() {
10952
+ var _this = this;
10953
+ var createdHighlights = [];
10954
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10955
+ args[_key] = arguments[_key];
10956
+ }
10957
+ args.forEach(function (arg) {
10958
+ var atoms = arg.atoms,
10959
+ bonds = arg.bonds,
10960
+ color = arg.color;
10961
+ if (typeof color !== 'string') {
10962
+ return;
10963
+ }
10964
+ if (!atoms && !bonds) {
10965
+ return;
10966
+ }
10967
+ var restruct = _this.editor.render.ctab;
10968
+ var _getValidInputOnly = getValidInputOnly(restruct.molecule, atoms, bonds),
10969
+ validAtoms = _getValidInputOnly.validAtoms,
10970
+ validBonds = _getValidInputOnly.validBonds;
10971
+ if (validAtoms.length === 0 && validBonds.length === 0) {
10972
+ return;
10973
+ }
10974
+ createdHighlights.push({
10975
+ atoms: validAtoms,
10976
+ bonds: validBonds,
10977
+ color: color
10978
+ });
10979
+ });
10980
+ var action = ketcherCore.fromHighlightCreate(this.editor.render.ctab, createdHighlights);
10981
+ this.editor.update(action);
10982
+ }
10983
+ }, {
10984
+ key: "clear",
10985
+ value: function clear() {
10986
+ var action = ketcherCore.fromHighlightClear(this.editor.render.ctab);
10987
+ this.editor.update(action);
10988
+ }
10989
+ }]);
10990
+ return Highlighter;
10991
+ }();
10992
+ function getValidInputOnly(struct, atoms, bonds) {
10993
+ if (!Array.isArray(atoms)) {
10994
+ atoms = [];
10995
+ }
10996
+ if (!Array.isArray(bonds)) {
10997
+ bonds = [];
10998
+ }
10999
+ var structAtoms = struct.atoms,
11000
+ structBonds = struct.bonds;
11001
+ if (atoms.length > 0) {
11002
+ atoms = atoms.filter(function (aid) {
11003
+ return structAtoms.has(aid);
11004
+ });
11005
+ }
11006
+ if (bonds.length > 0) {
11007
+ bonds = bonds.filter(function (bid) {
11008
+ return structBonds.has(bid);
11009
+ });
11010
+ }
11011
+ return {
11012
+ validAtoms: atoms,
11013
+ validBonds: bonds
11014
+ };
11015
+ }
11016
+
10928
11017
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
10929
11018
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
10930
11019
  var SCALE = 40;
@@ -10960,6 +11049,7 @@ var Editor$2 = function () {
10960
11049
  _defineProperty__default["default"](this, "historyStack", void 0);
10961
11050
  _defineProperty__default["default"](this, "historyPtr", void 0);
10962
11051
  _defineProperty__default["default"](this, "errorHandler", void 0);
11052
+ _defineProperty__default["default"](this, "highlights", void 0);
10963
11053
  _defineProperty__default["default"](this, "event", void 0);
10964
11054
  _defineProperty__default["default"](this, "lastEvent", void 0);
10965
11055
  this.render = new ketcherCore.Render(clientArea, Object.assign({
@@ -10970,6 +11060,7 @@ var Editor$2 = function () {
10970
11060
  this.historyStack = [];
10971
11061
  this.historyPtr = 0;
10972
11062
  this.errorHandler = null;
11063
+ this.highlights = new Highlighter(this);
10973
11064
  this.event = {
10974
11065
  message: new subscription.Subscription(),
10975
11066
  elementEdit: new subscription.PipelineSubscription(),
@@ -11118,48 +11209,10 @@ var Editor$2 = function () {
11118
11209
  value: function hover(ci, newTool) {
11119
11210
  var tool = newTool || this._tool;
11120
11211
  if ('ci' in tool && (!ci || tool.ci.map !== ci.map || tool.ci.id !== ci.id)) {
11121
- this.highlight(tool.ci, false);
11212
+ setHover(tool.ci, false, this.render);
11122
11213
  delete tool.ci;
11123
11214
  }
11124
- if (ci && this.highlight(ci, true)) tool.ci = ci;
11125
- }
11126
- }, {
11127
- key: "highlight",
11128
- value: function highlight(ci, visible) {
11129
- if (highlightTargets.indexOf(ci.map) === -1) {
11130
- return false;
11131
- }
11132
- var render = this.render;
11133
- var item = null;
11134
- if (ci.map === 'merge') {
11135
- Object.keys(ci.items).forEach(function (mp) {
11136
- ci.items[mp].forEach(function (dstId) {
11137
- item = render.ctab[mp].get(dstId);
11138
- if (item) {
11139
- item.setHighlight(visible, render);
11140
- }
11141
- });
11142
- });
11143
- return true;
11144
- }
11145
- if (ci.map === 'functionalGroups') ci.map = 'sgroups';
11146
- item = render.ctab[ci.map].get(ci.id);
11147
- if (!item) {
11148
- return true;
11149
- }
11150
- if (ci.map === 'sgroups' && item.item.type === 'DAT' || ci.map === 'sgroupData') {
11151
- var item1 = render.ctab.sgroups.get(ci.id);
11152
- if (item1) {
11153
- item1.setHighlight(visible, render);
11154
- }
11155
- var item2 = render.ctab.sgroupData.get(ci.id);
11156
- if (item2) {
11157
- item2.setHighlight(visible, render);
11158
- }
11159
- } else {
11160
- item.setHighlight(visible, render);
11161
- }
11162
- return true;
11215
+ if (ci && setHover(ci, true, this.render)) tool.ci = ci;
11163
11216
  }
11164
11217
  }, {
11165
11218
  key: "update",
@@ -11351,6 +11404,41 @@ function getStructCenter(ReStruct, selection) {
11351
11404
  var bb = ReStruct.getVBoxObj(selection || {});
11352
11405
  return ketcherCore.Vec2.lc2(bb.p0, 0.5, bb.p1, 0.5);
11353
11406
  }
11407
+ function setHover(ci, visible, render) {
11408
+ if (highlightTargets.indexOf(ci.map) === -1) {
11409
+ return false;
11410
+ }
11411
+ var item = null;
11412
+ if (ci.map === 'merge') {
11413
+ Object.keys(ci.items).forEach(function (mp) {
11414
+ ci.items[mp].forEach(function (dstId) {
11415
+ item = render.ctab[mp].get(dstId);
11416
+ if (item) {
11417
+ item.setHover(visible, render);
11418
+ }
11419
+ });
11420
+ });
11421
+ return true;
11422
+ }
11423
+ if (ci.map === 'functionalGroups') ci.map = 'sgroups';
11424
+ item = render.ctab[ci.map].get(ci.id);
11425
+ if (!item) {
11426
+ return true;
11427
+ }
11428
+ if (ci.map === 'sgroups' && item.item.type === 'DAT' || ci.map === 'sgroupData') {
11429
+ var item1 = render.ctab.sgroups.get(ci.id);
11430
+ if (item1) {
11431
+ item1.setHover(visible, render);
11432
+ }
11433
+ var item2 = render.ctab.sgroupData.get(ci.id);
11434
+ if (item2) {
11435
+ item2.setHover(visible, render);
11436
+ }
11437
+ } else {
11438
+ item.setHover(visible, render);
11439
+ }
11440
+ return true;
11441
+ }
11354
11442
 
11355
11443
  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"};
11356
11444
 
@@ -15926,11 +16014,11 @@ var EDITOR_STYLES = {
15926
16014
  fill: '#47b3ec',
15927
16015
  stroke: 'none'
15928
16016
  },
15929
- highlightStyle: {
16017
+ hoverStyle: {
15930
16018
  stroke: '#1a7090',
15931
16019
  'stroke-width': 1.2
15932
16020
  },
15933
- highlightStyleSimpleObject: {
16021
+ hoverStyleSimpleObject: {
15934
16022
  'stroke-opacity': 0.3
15935
16023
  }
15936
16024
  };
@@ -16825,8 +16913,8 @@ var KetcherBuilder = function () {
16825
16913
  initApp(element, staticResourcesUrl, {
16826
16914
  buttons: buttons || {},
16827
16915
  errorHandler: errorHandler || null,
16828
- version: "2.4.1" ,
16829
- buildDate: "2022-01-13T18:04:07" ,
16916
+ version: "2.4.2" ,
16917
+ buildDate: "2022-02-21T15:06:53" ,
16830
16918
  buildNumber: ''
16831
16919
  }, structService, resolve);
16832
16920
  });