ketcher-react 2.5.2 → 2.6.0-rc.1

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.
@@ -24,7 +24,7 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
24
24
  import _regeneratorRuntime from '@babel/runtime/regenerator';
25
25
  import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
26
26
  import _createClass from '@babel/runtime/helpers/createClass';
27
- import { KetSerializer, MolSerializer, Ketcher, FormatterFactory, StereLabelStyleType, StereoColoringType, Bond as Bond$2, Elements, AtomList, StereoLabel, findStereoAtoms, RxnArrowMode, SimpleObjectMode, SGroup, Pile, getStereoAtomsMap, identifyStructFormat, ChemicalMimeType, SdfSerializer, FunctionalGroupsProvider, ElementColor, formatProperties, Vec2, FunctionalGroup, Fragment as Fragment$1, OperationType, fromAtomsAttrs, fracAngle, Action, fromSgroupDeletion, fromFragmentDeletion, fromAtomAddition, fromBondAddition, Atom as Atom$2, bondChangingAction, fromBondsAttrs, fromChain, getItemsToFuse, getHoverToFuse, fromItemsFuse, 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, getPropertiesByImgFormat, Generics, TextCommand } from 'ketcher-core';
27
+ import { KetSerializer, MolSerializer, Ketcher, FormatterFactory, StereLabelStyleType, StereoColoringType, Bond as Bond$2, Elements, AtomList, StereoLabel, findStereoAtoms, RxnArrowMode, SimpleObjectMode, SGroup, Pile, getStereoAtomsMap, identifyStructFormat, ChemicalMimeType, SdfSerializer, FunctionalGroupsProvider, KetcherAsyncEvents, ElementColor, formatProperties, Vec2, FunctionalGroup, Fragment as Fragment$1, OperationType, fromAtomsAttrs, fracAngle, Action, fromSgroupDeletion, fromFragmentDeletion, fromAtomAddition, fromBondAddition, Atom as Atom$2, bondChangingAction, fromBondsAttrs, fromChain, getItemsToFuse, getHoverToFuse, fromItemsFuse, 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, fromNewCanvas, Struct, Render, fromDescriptorsAlign, setExpandSGroup, getPropertiesByFormat, StereoFlag, getPropertiesByImgFormat, Generics, TextCommand } from 'ketcher-core';
28
28
  import * as React from 'react';
29
29
  import React__default, { createRef, Component, useState, useEffect, useRef, useMemo, createElement, forwardRef, useCallback, useLayoutEffect, Fragment as Fragment$2 } from 'react';
30
30
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
@@ -37,7 +37,7 @@ import Ajv from 'ajv';
37
37
  import { pick, range, capitalize, omit, without, findLastIndex, findIndex, pickBy, isEmpty, isEqual, throttle, debounce, xor, upperFirst, escapeRegExp, flow, filter, reduce } from 'lodash/fp';
38
38
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
39
39
  import ReactDOM from 'react-dom';
40
- import { connect, useSelector, useDispatch, Provider } from 'react-redux';
40
+ import { connect, useDispatch, useSelector, Provider } from 'react-redux';
41
41
  import { combineReducers, createStore as createStore$1, applyMiddleware } from 'redux';
42
42
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
43
43
  import 'redux-logger';
@@ -2838,7 +2838,7 @@ var zoom = {
2838
2838
 
2839
2839
  var openHelpLink = function openHelpLink() {
2840
2840
  var _window$open;
2841
- return (_window$open = window.open("https://github.com/epam/ketcher/blob/".concat("v2.5.2\n", "/documentation/help.md#ketcher-overview"))) === null || _window$open === void 0 ? void 0 : _window$open.focus();
2841
+ return (_window$open = window.open("https://github.com/epam/ketcher/blob/".concat("v2.6.0-rc.1\n", "/documentation/help.md#ketcher-overview"))) === null || _window$open === void 0 ? void 0 : _window$open.focus();
2842
2842
  };
2843
2843
  var help = {
2844
2844
  help: {
@@ -8024,6 +8024,45 @@ var useInterval = function useInterval(callback, delay) {
8024
8024
  }, [delay]);
8025
8025
  };
8026
8026
 
8027
+ var KETCHER_INIT_EVENT_NAME = 'ketcher-init';
8028
+
8029
+ var useSubscriptionOnEvents = function useSubscriptionOnEvents() {
8030
+ var dispatch = useDispatch();
8031
+ var _useAppContext = useAppContext(),
8032
+ getKetcherInstance = _useAppContext.getKetcherInstance;
8033
+ var loadingHandler = function loadingHandler() {
8034
+ dispatch(indigoVerification(true));
8035
+ };
8036
+ var actionResultHandler = function actionResultHandler() {
8037
+ dispatch(indigoVerification(false));
8038
+ };
8039
+ var subscribe = function subscribe(ketcher) {
8040
+ ketcher.eventBus.addListener(KetcherAsyncEvents.LOADING, loadingHandler);
8041
+ ketcher.eventBus.addListener(KetcherAsyncEvents.SUCCESS, actionResultHandler);
8042
+ ketcher.eventBus.addListener(KetcherAsyncEvents.FAILURE, actionResultHandler);
8043
+ };
8044
+ var unsubscribe = function unsubscribe(ketcher) {
8045
+ ketcher.eventBus.removeListener(KetcherAsyncEvents.LOADING, loadingHandler);
8046
+ ketcher.eventBus.removeListener(KetcherAsyncEvents.SUCCESS, actionResultHandler);
8047
+ ketcher.eventBus.removeListener(KetcherAsyncEvents.FAILURE, actionResultHandler);
8048
+ };
8049
+ useEffect(function () {
8050
+ var subscribeOnInit = function subscribeOnInit() {
8051
+ subscribe(getKetcherInstance());
8052
+ };
8053
+ var unsubscribeOnUnMount = function unsubscribeOnUnMount() {
8054
+ unsubscribe(getKetcherInstance());
8055
+ };
8056
+ window.addEventListener(KETCHER_INIT_EVENT_NAME, function () {
8057
+ subscribeOnInit();
8058
+ });
8059
+ return function () {
8060
+ unsubscribeOnUnMount();
8061
+ window.removeEventListener(KETCHER_INIT_EVENT_NAME, subscribeOnInit);
8062
+ };
8063
+ }, []);
8064
+ };
8065
+
8027
8066
  var ArrowScroll = function ArrowScroll(_ref) {
8028
8067
  var startInView = _ref.startInView,
8029
8068
  endInView = _ref.endInView,
@@ -10499,10 +10538,10 @@ var APointTool = function () {
10499
10538
  key: "mousemove",
10500
10539
  value: function mousemove(event) {
10501
10540
  var struct = this.editor.render.ctab.molecule;
10502
- var ci = this.editor.findItem(event, ['atoms']);
10503
- if (ci) {
10504
- var atom = struct.atoms.get(ci.id);
10505
- if ((atom === null || atom === void 0 ? void 0 : atom.label) !== 'R#' && (atom === null || atom === void 0 ? void 0 : atom.rglabel) === null) this.editor.hover(ci);
10541
+ var closestItem = this.editor.findItem(event, ['atoms']);
10542
+ if (closestItem) {
10543
+ var atom = struct.atoms.get(closestItem.id);
10544
+ if ((atom === null || atom === void 0 ? void 0 : atom.label) !== 'R#' && (atom === null || atom === void 0 ? void 0 : atom.rglabel) === null) this.editor.hover(closestItem);
10506
10545
  } else {
10507
10546
  this.editor.hover(null);
10508
10547
  }
@@ -14439,12 +14478,12 @@ var TextTool = function () {
14439
14478
  key: "mousedown",
14440
14479
  value: function mousedown(event) {
14441
14480
  var render = this.editor.render;
14442
- var ci = this.editor.findItem(event, ['texts']);
14481
+ var closestItem = this.editor.findItem(event, ['texts']);
14443
14482
  this.editor.selection(null);
14444
- if (ci && ci.map === 'texts') {
14483
+ if (closestItem && closestItem.map === 'texts') {
14445
14484
  this.editor.hover(null);
14446
14485
  this.editor.selection({
14447
- texts: [ci.id]
14486
+ texts: [closestItem.id]
14448
14487
  });
14449
14488
  this.dragCtx = {
14450
14489
  xy0: render.page2obj(event),
@@ -14479,27 +14518,27 @@ var TextTool = function () {
14479
14518
  key: "click",
14480
14519
  value: function click(event) {
14481
14520
  var render = this.editor.render;
14482
- var ci = this.editor.findItem(event, ['texts']);
14521
+ var closestItem = this.editor.findItem(event, ['texts']);
14483
14522
  this.editor.hover(null);
14484
- if (!ci) {
14485
- propsDialog(this.editor, null, render.page2obj(event));
14523
+ if (!closestItem) {
14524
+ propsDialog(this.editor, null, render.page2obj(event), []);
14486
14525
  }
14487
14526
  return true;
14488
14527
  }
14489
14528
  }, {
14490
14529
  key: "dblclick",
14491
14530
  value: function dblclick(event) {
14492
- var ci = this.editor.findItem(event, ['texts']);
14531
+ var closestItem = this.editor.findItem(event, ['texts']);
14493
14532
  this.editor.hover(null);
14494
- if (ci.map === 'texts') {
14495
- propsDialog(this.editor, ci.id, ci.position);
14533
+ if (closestItem.map === 'texts') {
14534
+ propsDialog(this.editor, closestItem.id, closestItem.position, closestItem.pos);
14496
14535
  }
14497
14536
  return true;
14498
14537
  }
14499
14538
  }]);
14500
14539
  return TextTool;
14501
14540
  }();
14502
- function propsDialog(editor, id, position) {
14541
+ function propsDialog(editor, id, position, pos) {
14503
14542
  var struct = editor.render.ctab.molecule;
14504
14543
  var text = id || id === 0 ? struct.texts.get(id) : null;
14505
14544
  var origilContent = text ? text.content : '';
@@ -14507,12 +14546,13 @@ function propsDialog(editor, id, position) {
14507
14546
  content: origilContent,
14508
14547
  id: id,
14509
14548
  position: position,
14549
+ pos: pos,
14510
14550
  type: 'text'
14511
14551
  });
14512
14552
  res.then(function (_ref) {
14513
14553
  var content = _ref.content;
14514
14554
  if (!id && id !== 0 && content) {
14515
- editor.update(fromTextCreation(editor.render.ctab, content, position));
14555
+ editor.update(fromTextCreation(editor.render.ctab, content, position, pos));
14516
14556
  } else if (!content) {
14517
14557
  editor.update(fromTextDeletion(editor.render.ctab, id));
14518
14558
  } else if (content !== origilContent) {
@@ -14674,6 +14714,7 @@ var Editor$3 = function () {
14674
14714
  this.historyPtr = 0;
14675
14715
  this.errorHandler = null;
14676
14716
  this.highlights = new Highlighter(this);
14717
+ this.renderAndRecoordinateStruct = this.renderAndRecoordinateStruct.bind(this);
14677
14718
  this.event = {
14678
14719
  message: new Subscription(),
14679
14720
  elementEdit: new PipelineSubscription(),
@@ -14731,6 +14772,15 @@ var Editor$3 = function () {
14731
14772
  value: function clear() {
14732
14773
  this.struct(undefined);
14733
14774
  }
14775
+ }, {
14776
+ key: "renderAndRecoordinateStruct",
14777
+ value: function renderAndRecoordinateStruct(struct) {
14778
+ var action = fromNewCanvas(this.render.ctab, struct);
14779
+ this.update(action);
14780
+ getStructCenter(this.render.ctab);
14781
+ recoordinate(this);
14782
+ return this.render.ctab.molecule;
14783
+ }
14734
14784
  }, {
14735
14785
  key: "struct",
14736
14786
  value: function struct(value) {
@@ -14739,11 +14789,13 @@ var Editor$3 = function () {
14739
14789
  }
14740
14790
  this.selection(null);
14741
14791
  var struct = value || new Struct();
14742
- var action = fromNewCanvas(this.render.ctab, struct);
14743
- this.update(action);
14744
- getStructCenter(this.render.ctab);
14745
- recoordinate(this);
14746
- return this.render.ctab.molecule;
14792
+ return this.renderAndRecoordinateStruct(struct);
14793
+ }
14794
+ }, {
14795
+ key: "structToAddFragment",
14796
+ value: function structToAddFragment(value) {
14797
+ var superStruct = value.mergeInto(this.render.ctab.molecule);
14798
+ return this.renderAndRecoordinateStruct(superStruct);
14747
14799
  }
14748
14800
  }, {
14749
14801
  key: "options",
@@ -15258,8 +15310,12 @@ function setupEditor(editor, props) {
15258
15310
  Object.keys(editor.event).forEach(function (name) {
15259
15311
  var eventName = "on".concat(upperFirst(name));
15260
15312
  if (props[eventName] !== oldProps[eventName]) {
15261
- if (oldProps[eventName]) editor.event[name].remove(oldProps[eventName]);
15262
- if (props[eventName]) editor.event[name].add(props[eventName]);
15313
+ if (oldProps[eventName]) {
15314
+ editor.event[name].remove(oldProps[eventName]);
15315
+ }
15316
+ if (props[eventName]) {
15317
+ editor.event[name].add(props[eventName]);
15318
+ }
15263
15319
  }
15264
15320
  });
15265
15321
  }
@@ -18987,7 +19043,8 @@ var SaveDialog = function (_Component) {
18987
19043
  }) : _this.isImageFormat(format) ? jsx("div", {
18988
19044
  className: classes$j.imageContainer,
18989
19045
  children: !isCleanStruct && jsx("img", {
18990
- src: "data:image/".concat(format, "+xml;base64,").concat(imageSrc)
19046
+ src: "data:image/".concat(format, "+xml;base64,").concat(imageSrc),
19047
+ alt: "".concat(format, " preview")
18991
19048
  })
18992
19049
  }) : jsx("div", {
18993
19050
  className: classes$j.previewBackground,
@@ -19082,7 +19139,7 @@ var SaveDialog = function (_Component) {
19082
19139
  _this.isRxn = _this.props.struct.hasRxnArrow();
19083
19140
  _this.textAreaRef = createRef();
19084
19141
  var formats = [_this.isRxn ? 'rxn' : 'mol', 'smiles', 'ket'];
19085
- if (_this.props.server) formats.push(_this.isRxn ? 'rxnV3000' : 'molV3000', 'smilesExt', 'smarts', 'inChI', 'inChIAuxInfo', 'cml', 'svg', 'png');
19142
+ if (_this.props.server) formats.push(_this.isRxn ? 'rxnV3000' : 'molV3000', 'smilesExt', 'smarts', 'inChI', 'inChIAuxInfo', 'cml', 'svg', 'png', 'cdxml');
19086
19143
  _this.saveSchema = saveSchema;
19087
19144
  _this.saveSchema.properties.format = Object.assign(_this.saveSchema.properties.format, {
19088
19145
  "enum": formats,
@@ -21141,7 +21198,7 @@ var Text = function Text(props) {
21141
21198
  };
21142
21199
  };
21143
21200
  var keyBindingFn = function keyBindingFn(e) {
21144
- if (e.keyCode === 13) {
21201
+ if (e.key === 'Enter') {
21145
21202
  e.stopPropagation();
21146
21203
  }
21147
21204
  return getDefaultKeyBinding(e);
@@ -21559,6 +21616,7 @@ var App = function App(props) {
21559
21616
  var checkServer = props.checkServer;
21560
21617
  var _useSettingsContext = useSettingsContext(),
21561
21618
  staticResourcesUrl = _useSettingsContext.staticResourcesUrl;
21619
+ useSubscriptionOnEvents();
21562
21620
  useEffect(function () {
21563
21621
  checkServer();
21564
21622
  dispatch(initFGTemplates(staticResourcesUrl));
@@ -21669,8 +21727,8 @@ var KetcherBuilder = function () {
21669
21727
  initApp(element, staticResourcesUrl, {
21670
21728
  buttons: buttons || {},
21671
21729
  errorHandler: errorHandler || null,
21672
- version: "2.5.2" ,
21673
- buildDate: "2022-09-07T08:32:56" ,
21730
+ version: "2.6.0-rc.1" ,
21731
+ buildDate: "2022-10-14T12:12:12" ,
21674
21732
  buildNumber: ''
21675
21733
  }, structService, resolve);
21676
21734
  });
@@ -21763,12 +21821,14 @@ function Editor(props) {
21763
21821
  }),
21764
21822
  height = _useResizeObserver.height,
21765
21823
  width = _useResizeObserver.width;
21824
+ var ketcherInitEvent = new Event(KETCHER_INIT_EVENT_NAME);
21766
21825
  useEffect(function () {
21767
21826
  buildKetcherAsync(_objectSpread(_objectSpread({}, props), {}, {
21768
21827
  element: rootElRef.current
21769
21828
  })).then(function (ketcher) {
21770
21829
  if (typeof onInit === 'function') {
21771
21830
  onInit(ketcher);
21831
+ window.dispatchEvent(ketcherInitEvent);
21772
21832
  }
21773
21833
  });
21774
21834
  }, []);
@@ -21778,5 +21838,5 @@ function Editor(props) {
21778
21838
  });
21779
21839
  }
21780
21840
 
21781
- export { Editor };
21841
+ export { Editor, KETCHER_INIT_EVENT_NAME };
21782
21842
  //# sourceMappingURL=index.modern.js.map