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.
@@ -0,0 +1,16 @@
1
+ /****************************************************************************
2
+ * Copyright 2021 EPAM Systems
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ ***************************************************************************/
16
+ export declare const KETCHER_INIT_EVENT_NAME = "ketcher-init";
@@ -18,3 +18,4 @@ export * from './useResizeObserver';
18
18
  export * from './useFormContext';
19
19
  export * from './useAppContext';
20
20
  export * from './useInterval';
21
+ export * from './useSubscribtionOnEvents';
@@ -0,0 +1,16 @@
1
+ /****************************************************************************
2
+ * Copyright 2021 EPAM Systems
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ ***************************************************************************/
16
+ export declare const useSubscriptionOnEvents: () => void;
package/dist/index.d.ts CHANGED
@@ -15,3 +15,4 @@
15
15
  ***************************************************************************/
16
16
  export * from './Editor';
17
17
  export * from './script';
18
+ export * from './constants';
package/dist/index.js CHANGED
@@ -336,7 +336,9 @@ var ClipArea = function (_Component) {
336
336
  this.target = this.props.target || el.parentNode;
337
337
  this.listeners = {
338
338
  mouseup: function mouseup(event) {
339
- if (el === event.target || !isActiveElement(event.target) && _this2.props.focused()) autofocus(el);
339
+ if (el === event.target || !isActiveElement(event.target) && _this2.props.focused()) {
340
+ autoselect(el);
341
+ }
340
342
  },
341
343
  mousedown: function mousedown(event) {
342
344
  if (event.shiftKey && !isActiveElement(event.target)) event.preventDefault();
@@ -399,9 +401,8 @@ function isActiveElement(el) {
399
401
  if (el.tagName === 'INPUT' && el.type === 'button') return false;
400
402
  return ['INPUT', 'SELECT', 'TEXTAREA', 'OPTION', 'LABEL'].includes(el.tagName);
401
403
  }
402
- function autofocus(cliparea) {
404
+ function autoselect(cliparea) {
403
405
  cliparea.value = ' ';
404
- cliparea.focus();
405
406
  cliparea.select();
406
407
  }
407
408
  function _copy(cb, data) {
@@ -2898,7 +2899,7 @@ var zoom = {
2898
2899
 
2899
2900
  var openHelpLink = function openHelpLink() {
2900
2901
  var _window$open;
2901
- 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();
2902
+ 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();
2902
2903
  };
2903
2904
  var help = {
2904
2905
  help: {
@@ -8084,6 +8085,45 @@ var useInterval = function useInterval(callback, delay) {
8084
8085
  }, [delay]);
8085
8086
  };
8086
8087
 
8088
+ var KETCHER_INIT_EVENT_NAME = 'ketcher-init';
8089
+
8090
+ var useSubscriptionOnEvents = function useSubscriptionOnEvents() {
8091
+ var dispatch = reactRedux.useDispatch();
8092
+ var _useAppContext = useAppContext(),
8093
+ getKetcherInstance = _useAppContext.getKetcherInstance;
8094
+ var loadingHandler = function loadingHandler() {
8095
+ dispatch(indigoVerification(true));
8096
+ };
8097
+ var actionResultHandler = function actionResultHandler() {
8098
+ dispatch(indigoVerification(false));
8099
+ };
8100
+ var subscribe = function subscribe(ketcher) {
8101
+ ketcher.eventBus.addListener(ketcherCore.KetcherAsyncEvents.LOADING, loadingHandler);
8102
+ ketcher.eventBus.addListener(ketcherCore.KetcherAsyncEvents.SUCCESS, actionResultHandler);
8103
+ ketcher.eventBus.addListener(ketcherCore.KetcherAsyncEvents.FAILURE, actionResultHandler);
8104
+ };
8105
+ var unsubscribe = function unsubscribe(ketcher) {
8106
+ ketcher.eventBus.removeListener(ketcherCore.KetcherAsyncEvents.LOADING, loadingHandler);
8107
+ ketcher.eventBus.removeListener(ketcherCore.KetcherAsyncEvents.SUCCESS, actionResultHandler);
8108
+ ketcher.eventBus.removeListener(ketcherCore.KetcherAsyncEvents.FAILURE, actionResultHandler);
8109
+ };
8110
+ React.useEffect(function () {
8111
+ var subscribeOnInit = function subscribeOnInit() {
8112
+ subscribe(getKetcherInstance());
8113
+ };
8114
+ var unsubscribeOnUnMount = function unsubscribeOnUnMount() {
8115
+ unsubscribe(getKetcherInstance());
8116
+ };
8117
+ window.addEventListener(KETCHER_INIT_EVENT_NAME, function () {
8118
+ subscribeOnInit();
8119
+ });
8120
+ return function () {
8121
+ unsubscribeOnUnMount();
8122
+ window.removeEventListener(KETCHER_INIT_EVENT_NAME, subscribeOnInit);
8123
+ };
8124
+ }, []);
8125
+ };
8126
+
8087
8127
  var ArrowScroll = function ArrowScroll(_ref) {
8088
8128
  var startInView = _ref.startInView,
8089
8129
  endInView = _ref.endInView,
@@ -10559,10 +10599,10 @@ var APointTool = function () {
10559
10599
  key: "mousemove",
10560
10600
  value: function mousemove(event) {
10561
10601
  var struct = this.editor.render.ctab.molecule;
10562
- var ci = this.editor.findItem(event, ['atoms']);
10563
- if (ci) {
10564
- var atom = struct.atoms.get(ci.id);
10565
- 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);
10602
+ var closestItem = this.editor.findItem(event, ['atoms']);
10603
+ if (closestItem) {
10604
+ var atom = struct.atoms.get(closestItem.id);
10605
+ 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);
10566
10606
  } else {
10567
10607
  this.editor.hover(null);
10568
10608
  }
@@ -14499,12 +14539,12 @@ var TextTool = function () {
14499
14539
  key: "mousedown",
14500
14540
  value: function mousedown(event) {
14501
14541
  var render = this.editor.render;
14502
- var ci = this.editor.findItem(event, ['texts']);
14542
+ var closestItem = this.editor.findItem(event, ['texts']);
14503
14543
  this.editor.selection(null);
14504
- if (ci && ci.map === 'texts') {
14544
+ if (closestItem && closestItem.map === 'texts') {
14505
14545
  this.editor.hover(null);
14506
14546
  this.editor.selection({
14507
- texts: [ci.id]
14547
+ texts: [closestItem.id]
14508
14548
  });
14509
14549
  this.dragCtx = {
14510
14550
  xy0: render.page2obj(event),
@@ -14539,27 +14579,27 @@ var TextTool = function () {
14539
14579
  key: "click",
14540
14580
  value: function click(event) {
14541
14581
  var render = this.editor.render;
14542
- var ci = this.editor.findItem(event, ['texts']);
14582
+ var closestItem = this.editor.findItem(event, ['texts']);
14543
14583
  this.editor.hover(null);
14544
- if (!ci) {
14545
- propsDialog(this.editor, null, render.page2obj(event));
14584
+ if (!closestItem) {
14585
+ propsDialog(this.editor, null, render.page2obj(event), []);
14546
14586
  }
14547
14587
  return true;
14548
14588
  }
14549
14589
  }, {
14550
14590
  key: "dblclick",
14551
14591
  value: function dblclick(event) {
14552
- var ci = this.editor.findItem(event, ['texts']);
14592
+ var closestItem = this.editor.findItem(event, ['texts']);
14553
14593
  this.editor.hover(null);
14554
- if (ci.map === 'texts') {
14555
- propsDialog(this.editor, ci.id, ci.position);
14594
+ if (closestItem.map === 'texts') {
14595
+ propsDialog(this.editor, closestItem.id, closestItem.position, closestItem.pos);
14556
14596
  }
14557
14597
  return true;
14558
14598
  }
14559
14599
  }]);
14560
14600
  return TextTool;
14561
14601
  }();
14562
- function propsDialog(editor, id, position) {
14602
+ function propsDialog(editor, id, position, pos) {
14563
14603
  var struct = editor.render.ctab.molecule;
14564
14604
  var text = id || id === 0 ? struct.texts.get(id) : null;
14565
14605
  var origilContent = text ? text.content : '';
@@ -14567,12 +14607,13 @@ function propsDialog(editor, id, position) {
14567
14607
  content: origilContent,
14568
14608
  id: id,
14569
14609
  position: position,
14610
+ pos: pos,
14570
14611
  type: 'text'
14571
14612
  });
14572
14613
  res.then(function (_ref) {
14573
14614
  var content = _ref.content;
14574
14615
  if (!id && id !== 0 && content) {
14575
- editor.update(ketcherCore.fromTextCreation(editor.render.ctab, content, position));
14616
+ editor.update(ketcherCore.fromTextCreation(editor.render.ctab, content, position, pos));
14576
14617
  } else if (!content) {
14577
14618
  editor.update(ketcherCore.fromTextDeletion(editor.render.ctab, id));
14578
14619
  } else if (content !== origilContent) {
@@ -14734,6 +14775,7 @@ var Editor$3 = function () {
14734
14775
  this.historyPtr = 0;
14735
14776
  this.errorHandler = null;
14736
14777
  this.highlights = new Highlighter(this);
14778
+ this.renderAndRecoordinateStruct = this.renderAndRecoordinateStruct.bind(this);
14737
14779
  this.event = {
14738
14780
  message: new subscription.Subscription(),
14739
14781
  elementEdit: new subscription.PipelineSubscription(),
@@ -14791,6 +14833,15 @@ var Editor$3 = function () {
14791
14833
  value: function clear() {
14792
14834
  this.struct(undefined);
14793
14835
  }
14836
+ }, {
14837
+ key: "renderAndRecoordinateStruct",
14838
+ value: function renderAndRecoordinateStruct(struct) {
14839
+ var action = ketcherCore.fromNewCanvas(this.render.ctab, struct);
14840
+ this.update(action);
14841
+ getStructCenter(this.render.ctab);
14842
+ recoordinate(this);
14843
+ return this.render.ctab.molecule;
14844
+ }
14794
14845
  }, {
14795
14846
  key: "struct",
14796
14847
  value: function struct(value) {
@@ -14799,11 +14850,13 @@ var Editor$3 = function () {
14799
14850
  }
14800
14851
  this.selection(null);
14801
14852
  var struct = value || new ketcherCore.Struct();
14802
- var action = ketcherCore.fromNewCanvas(this.render.ctab, struct);
14803
- this.update(action);
14804
- getStructCenter(this.render.ctab);
14805
- recoordinate(this);
14806
- return this.render.ctab.molecule;
14853
+ return this.renderAndRecoordinateStruct(struct);
14854
+ }
14855
+ }, {
14856
+ key: "structToAddFragment",
14857
+ value: function structToAddFragment(value) {
14858
+ var superStruct = value.mergeInto(this.render.ctab.molecule);
14859
+ return this.renderAndRecoordinateStruct(superStruct);
14807
14860
  }
14808
14861
  }, {
14809
14862
  key: "options",
@@ -15318,8 +15371,12 @@ function setupEditor(editor, props) {
15318
15371
  Object.keys(editor.event).forEach(function (name) {
15319
15372
  var eventName = "on".concat(fp.upperFirst(name));
15320
15373
  if (props[eventName] !== oldProps[eventName]) {
15321
- if (oldProps[eventName]) editor.event[name].remove(oldProps[eventName]);
15322
- if (props[eventName]) editor.event[name].add(props[eventName]);
15374
+ if (oldProps[eventName]) {
15375
+ editor.event[name].remove(oldProps[eventName]);
15376
+ }
15377
+ if (props[eventName]) {
15378
+ editor.event[name].add(props[eventName]);
15379
+ }
15323
15380
  }
15324
15381
  });
15325
15382
  }
@@ -19047,7 +19104,8 @@ var SaveDialog = function (_Component) {
19047
19104
  }) : _this.isImageFormat(format) ? jsxRuntime.jsx("div", {
19048
19105
  className: classes$j.imageContainer,
19049
19106
  children: !isCleanStruct && jsxRuntime.jsx("img", {
19050
- src: "data:image/".concat(format, "+xml;base64,").concat(imageSrc)
19107
+ src: "data:image/".concat(format, "+xml;base64,").concat(imageSrc),
19108
+ alt: "".concat(format, " preview")
19051
19109
  })
19052
19110
  }) : jsxRuntime.jsx("div", {
19053
19111
  className: classes$j.previewBackground,
@@ -19142,7 +19200,7 @@ var SaveDialog = function (_Component) {
19142
19200
  _this.isRxn = _this.props.struct.hasRxnArrow();
19143
19201
  _this.textAreaRef = React.createRef();
19144
19202
  var formats = [_this.isRxn ? 'rxn' : 'mol', 'smiles', 'ket'];
19145
- if (_this.props.server) formats.push(_this.isRxn ? 'rxnV3000' : 'molV3000', 'smilesExt', 'smarts', 'inChI', 'inChIAuxInfo', 'cml', 'svg', 'png');
19203
+ if (_this.props.server) formats.push(_this.isRxn ? 'rxnV3000' : 'molV3000', 'smilesExt', 'smarts', 'inChI', 'inChIAuxInfo', 'cml', 'svg', 'png', 'cdxml');
19146
19204
  _this.saveSchema = saveSchema;
19147
19205
  _this.saveSchema.properties.format = Object.assign(_this.saveSchema.properties.format, {
19148
19206
  "enum": formats,
@@ -21201,7 +21259,7 @@ var Text = function Text(props) {
21201
21259
  };
21202
21260
  };
21203
21261
  var keyBindingFn = function keyBindingFn(e) {
21204
- if (e.keyCode === 13) {
21262
+ if (e.key === 'Enter') {
21205
21263
  e.stopPropagation();
21206
21264
  }
21207
21265
  return draftJs.getDefaultKeyBinding(e);
@@ -21619,6 +21677,7 @@ var App = function App(props) {
21619
21677
  var checkServer = props.checkServer;
21620
21678
  var _useSettingsContext = useSettingsContext(),
21621
21679
  staticResourcesUrl = _useSettingsContext.staticResourcesUrl;
21680
+ useSubscriptionOnEvents();
21622
21681
  React.useEffect(function () {
21623
21682
  checkServer();
21624
21683
  dispatch(initFGTemplates(staticResourcesUrl));
@@ -21729,8 +21788,8 @@ var KetcherBuilder = function () {
21729
21788
  initApp(element, staticResourcesUrl, {
21730
21789
  buttons: buttons || {},
21731
21790
  errorHandler: errorHandler || null,
21732
- version: "2.5.1" ,
21733
- buildDate: "2022-06-17T15:19:17" ,
21791
+ version: "2.6.0-rc.1" ,
21792
+ buildDate: "2022-10-14T12:12:12" ,
21734
21793
  buildNumber: ''
21735
21794
  }, structService, resolve);
21736
21795
  });
@@ -21823,12 +21882,14 @@ function Editor(props) {
21823
21882
  }),
21824
21883
  height = _useResizeObserver.height,
21825
21884
  width = _useResizeObserver.width;
21885
+ var ketcherInitEvent = new Event(KETCHER_INIT_EVENT_NAME);
21826
21886
  React.useEffect(function () {
21827
21887
  buildKetcherAsync(_objectSpread(_objectSpread({}, props), {}, {
21828
21888
  element: rootElRef.current
21829
21889
  })).then(function (ketcher) {
21830
21890
  if (typeof onInit === 'function') {
21831
21891
  onInit(ketcher);
21892
+ window.dispatchEvent(ketcherInitEvent);
21832
21893
  }
21833
21894
  });
21834
21895
  }, []);
@@ -21839,4 +21900,5 @@ function Editor(props) {
21839
21900
  }
21840
21901
 
21841
21902
  exports.Editor = Editor;
21903
+ exports.KETCHER_INIT_EVENT_NAME = KETCHER_INIT_EVENT_NAME;
21842
21904
  //# sourceMappingURL=index.js.map