ketcher-react 2.5.1 → 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';
@@ -275,7 +275,9 @@ var ClipArea = function (_Component) {
275
275
  this.target = this.props.target || el.parentNode;
276
276
  this.listeners = {
277
277
  mouseup: function mouseup(event) {
278
- if (el === event.target || !isActiveElement(event.target) && _this2.props.focused()) autofocus(el);
278
+ if (el === event.target || !isActiveElement(event.target) && _this2.props.focused()) {
279
+ autoselect(el);
280
+ }
279
281
  },
280
282
  mousedown: function mousedown(event) {
281
283
  if (event.shiftKey && !isActiveElement(event.target)) event.preventDefault();
@@ -338,9 +340,8 @@ function isActiveElement(el) {
338
340
  if (el.tagName === 'INPUT' && el.type === 'button') return false;
339
341
  return ['INPUT', 'SELECT', 'TEXTAREA', 'OPTION', 'LABEL'].includes(el.tagName);
340
342
  }
341
- function autofocus(cliparea) {
343
+ function autoselect(cliparea) {
342
344
  cliparea.value = ' ';
343
- cliparea.focus();
344
345
  cliparea.select();
345
346
  }
346
347
  function _copy(cb, data) {
@@ -2837,7 +2838,7 @@ var zoom = {
2837
2838
 
2838
2839
  var openHelpLink = function openHelpLink() {
2839
2840
  var _window$open;
2840
- return (_window$open = window.open("https://github.com/epam/ketcher/blob/".concat("v2.5.0\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();
2841
2842
  };
2842
2843
  var help = {
2843
2844
  help: {
@@ -8023,6 +8024,45 @@ var useInterval = function useInterval(callback, delay) {
8023
8024
  }, [delay]);
8024
8025
  };
8025
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
+
8026
8066
  var ArrowScroll = function ArrowScroll(_ref) {
8027
8067
  var startInView = _ref.startInView,
8028
8068
  endInView = _ref.endInView,
@@ -10498,10 +10538,10 @@ var APointTool = function () {
10498
10538
  key: "mousemove",
10499
10539
  value: function mousemove(event) {
10500
10540
  var struct = this.editor.render.ctab.molecule;
10501
- var ci = this.editor.findItem(event, ['atoms']);
10502
- if (ci) {
10503
- var atom = struct.atoms.get(ci.id);
10504
- 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);
10505
10545
  } else {
10506
10546
  this.editor.hover(null);
10507
10547
  }
@@ -14438,12 +14478,12 @@ var TextTool = function () {
14438
14478
  key: "mousedown",
14439
14479
  value: function mousedown(event) {
14440
14480
  var render = this.editor.render;
14441
- var ci = this.editor.findItem(event, ['texts']);
14481
+ var closestItem = this.editor.findItem(event, ['texts']);
14442
14482
  this.editor.selection(null);
14443
- if (ci && ci.map === 'texts') {
14483
+ if (closestItem && closestItem.map === 'texts') {
14444
14484
  this.editor.hover(null);
14445
14485
  this.editor.selection({
14446
- texts: [ci.id]
14486
+ texts: [closestItem.id]
14447
14487
  });
14448
14488
  this.dragCtx = {
14449
14489
  xy0: render.page2obj(event),
@@ -14478,27 +14518,27 @@ var TextTool = function () {
14478
14518
  key: "click",
14479
14519
  value: function click(event) {
14480
14520
  var render = this.editor.render;
14481
- var ci = this.editor.findItem(event, ['texts']);
14521
+ var closestItem = this.editor.findItem(event, ['texts']);
14482
14522
  this.editor.hover(null);
14483
- if (!ci) {
14484
- propsDialog(this.editor, null, render.page2obj(event));
14523
+ if (!closestItem) {
14524
+ propsDialog(this.editor, null, render.page2obj(event), []);
14485
14525
  }
14486
14526
  return true;
14487
14527
  }
14488
14528
  }, {
14489
14529
  key: "dblclick",
14490
14530
  value: function dblclick(event) {
14491
- var ci = this.editor.findItem(event, ['texts']);
14531
+ var closestItem = this.editor.findItem(event, ['texts']);
14492
14532
  this.editor.hover(null);
14493
- if (ci.map === 'texts') {
14494
- propsDialog(this.editor, ci.id, ci.position);
14533
+ if (closestItem.map === 'texts') {
14534
+ propsDialog(this.editor, closestItem.id, closestItem.position, closestItem.pos);
14495
14535
  }
14496
14536
  return true;
14497
14537
  }
14498
14538
  }]);
14499
14539
  return TextTool;
14500
14540
  }();
14501
- function propsDialog(editor, id, position) {
14541
+ function propsDialog(editor, id, position, pos) {
14502
14542
  var struct = editor.render.ctab.molecule;
14503
14543
  var text = id || id === 0 ? struct.texts.get(id) : null;
14504
14544
  var origilContent = text ? text.content : '';
@@ -14506,12 +14546,13 @@ function propsDialog(editor, id, position) {
14506
14546
  content: origilContent,
14507
14547
  id: id,
14508
14548
  position: position,
14549
+ pos: pos,
14509
14550
  type: 'text'
14510
14551
  });
14511
14552
  res.then(function (_ref) {
14512
14553
  var content = _ref.content;
14513
14554
  if (!id && id !== 0 && content) {
14514
- editor.update(fromTextCreation(editor.render.ctab, content, position));
14555
+ editor.update(fromTextCreation(editor.render.ctab, content, position, pos));
14515
14556
  } else if (!content) {
14516
14557
  editor.update(fromTextDeletion(editor.render.ctab, id));
14517
14558
  } else if (content !== origilContent) {
@@ -14673,6 +14714,7 @@ var Editor$3 = function () {
14673
14714
  this.historyPtr = 0;
14674
14715
  this.errorHandler = null;
14675
14716
  this.highlights = new Highlighter(this);
14717
+ this.renderAndRecoordinateStruct = this.renderAndRecoordinateStruct.bind(this);
14676
14718
  this.event = {
14677
14719
  message: new Subscription(),
14678
14720
  elementEdit: new PipelineSubscription(),
@@ -14730,6 +14772,15 @@ var Editor$3 = function () {
14730
14772
  value: function clear() {
14731
14773
  this.struct(undefined);
14732
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
+ }
14733
14784
  }, {
14734
14785
  key: "struct",
14735
14786
  value: function struct(value) {
@@ -14738,11 +14789,13 @@ var Editor$3 = function () {
14738
14789
  }
14739
14790
  this.selection(null);
14740
14791
  var struct = value || new Struct();
14741
- var action = fromNewCanvas(this.render.ctab, struct);
14742
- this.update(action);
14743
- getStructCenter(this.render.ctab);
14744
- recoordinate(this);
14745
- 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);
14746
14799
  }
14747
14800
  }, {
14748
14801
  key: "options",
@@ -15257,8 +15310,12 @@ function setupEditor(editor, props) {
15257
15310
  Object.keys(editor.event).forEach(function (name) {
15258
15311
  var eventName = "on".concat(upperFirst(name));
15259
15312
  if (props[eventName] !== oldProps[eventName]) {
15260
- if (oldProps[eventName]) editor.event[name].remove(oldProps[eventName]);
15261
- 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
+ }
15262
15319
  }
15263
15320
  });
15264
15321
  }
@@ -18986,7 +19043,8 @@ var SaveDialog = function (_Component) {
18986
19043
  }) : _this.isImageFormat(format) ? jsx("div", {
18987
19044
  className: classes$j.imageContainer,
18988
19045
  children: !isCleanStruct && jsx("img", {
18989
- src: "data:image/".concat(format, "+xml;base64,").concat(imageSrc)
19046
+ src: "data:image/".concat(format, "+xml;base64,").concat(imageSrc),
19047
+ alt: "".concat(format, " preview")
18990
19048
  })
18991
19049
  }) : jsx("div", {
18992
19050
  className: classes$j.previewBackground,
@@ -19081,7 +19139,7 @@ var SaveDialog = function (_Component) {
19081
19139
  _this.isRxn = _this.props.struct.hasRxnArrow();
19082
19140
  _this.textAreaRef = createRef();
19083
19141
  var formats = [_this.isRxn ? 'rxn' : 'mol', 'smiles', 'ket'];
19084
- 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');
19085
19143
  _this.saveSchema = saveSchema;
19086
19144
  _this.saveSchema.properties.format = Object.assign(_this.saveSchema.properties.format, {
19087
19145
  "enum": formats,
@@ -21140,7 +21198,7 @@ var Text = function Text(props) {
21140
21198
  };
21141
21199
  };
21142
21200
  var keyBindingFn = function keyBindingFn(e) {
21143
- if (e.keyCode === 13) {
21201
+ if (e.key === 'Enter') {
21144
21202
  e.stopPropagation();
21145
21203
  }
21146
21204
  return getDefaultKeyBinding(e);
@@ -21558,6 +21616,7 @@ var App = function App(props) {
21558
21616
  var checkServer = props.checkServer;
21559
21617
  var _useSettingsContext = useSettingsContext(),
21560
21618
  staticResourcesUrl = _useSettingsContext.staticResourcesUrl;
21619
+ useSubscriptionOnEvents();
21561
21620
  useEffect(function () {
21562
21621
  checkServer();
21563
21622
  dispatch(initFGTemplates(staticResourcesUrl));
@@ -21668,8 +21727,8 @@ var KetcherBuilder = function () {
21668
21727
  initApp(element, staticResourcesUrl, {
21669
21728
  buttons: buttons || {},
21670
21729
  errorHandler: errorHandler || null,
21671
- version: "2.5.1" ,
21672
- buildDate: "2022-06-17T15:19:17" ,
21730
+ version: "2.6.0-rc.1" ,
21731
+ buildDate: "2022-10-14T12:12:12" ,
21673
21732
  buildNumber: ''
21674
21733
  }, structService, resolve);
21675
21734
  });
@@ -21762,12 +21821,14 @@ function Editor(props) {
21762
21821
  }),
21763
21822
  height = _useResizeObserver.height,
21764
21823
  width = _useResizeObserver.width;
21824
+ var ketcherInitEvent = new Event(KETCHER_INIT_EVENT_NAME);
21765
21825
  useEffect(function () {
21766
21826
  buildKetcherAsync(_objectSpread(_objectSpread({}, props), {}, {
21767
21827
  element: rootElRef.current
21768
21828
  })).then(function (ketcher) {
21769
21829
  if (typeof onInit === 'function') {
21770
21830
  onInit(ketcher);
21831
+ window.dispatchEvent(ketcherInitEvent);
21771
21832
  }
21772
21833
  });
21773
21834
  }, []);
@@ -21777,5 +21838,5 @@ function Editor(props) {
21777
21838
  });
21778
21839
  }
21779
21840
 
21780
- export { Editor };
21841
+ export { Editor, KETCHER_INIT_EVENT_NAME };
21781
21842
  //# sourceMappingURL=index.modern.js.map