ketcher-react 2.15.0-rc.1 → 2.15.0-rc.3

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$2 from '@babel/runtime/helpers/classCallCheck';
26
26
  import _createClass$1 from '@babel/runtime/helpers/createClass';
27
- import { KetSerializer, MolSerializer, Ketcher, defaultBondThickness, FormatterFactory, StereLabelStyleType, StereoColoringType, ShowHydrogenLabels, ShowHydrogenLabelNames, SdfSerializer, Bond as Bond$2, Elements, AtomList, StereoLabel, isAttachmentBond, Atom as Atom$2, findStereoAtoms, RxnArrowMode, SimpleObjectMode, emitEventRequestIsFinished, SGroup as SGroup$1, Pile, getStereoAtomsMap, identifyStructFormat, SupportedFormat, ChemicalMimeType, RenderStruct, Struct, FunctionalGroupsProvider, SaltsAndSolventsProvider, KetcherAsyncEvents, ElementColor, Vec2, fromMultipleMove, scrollByVector, FunctionalGroup, Scale, fromSgroupDeletion, fromFragmentDeletion, mergeMapOfItemsToSet, vectorUtils, fromBondAddition, Action, fromAtomAddition, fromAtomsAttrs, checkOverlapping, fromSeveralSgroupAddition, expandSGroupWithMultipleAttachmentPoint, SgContexts, fromSgroupAction, fromItemsFuse, ReBond, setExpandSGroup, fromBondsAttrs, OperationType, ReStruct, fromSimpleObjectResizing, fromArrowResizing, getItemsToFuse, getHoverToFuse, fromTextDeletion, fromTextUpdating, isCloseToEdgeOfCanvas, isCloseToEdgeOfScreen, getDirections, shiftAndExtendCanvasByVector, formatProperties, Fragment as Fragment$1, fromRGroupAttachmentPointUpdate, fromOneBondDeletion, bondChangingAction, fromChain, fromStereoFlagUpdate, fromOneAtomDeletion, fromArrowDeletion, fromPlusDeletion, fromSimpleObjectDeletion, fromRGroupAttachmentPointDeletion, fromPaste, fromTemplateOnAtom, RGroup as RGroup$2, fromRGroupFragment, fromUpdateIfThen, fromRGroupAttrs, fromArrowAddition, fromPlusAddition, fromRotate, fromFlip, fromSimpleObjectAddition, fromTemplateOnBondAction, fromTemplateOnCanvas, fromTextCreation, fromHighlightCreate, fromHighlightClear, fromNewCanvas, Render, fromDescriptorsAlign, atomGetAttr, getPropertiesByFormat, StereoFlag, getPropertiesByImgFormat, b64toBlob, Generics, TextCommand, DefaultStructServiceOptions } from 'ketcher-core';
27
+ import { KetSerializer, MolSerializer, Ketcher, defaultBondThickness, FormatterFactory, StereLabelStyleType, StereoColoringType, ShowHydrogenLabels, ShowHydrogenLabelNames, SdfSerializer, Bond as Bond$2, Elements, AtomList, StereoLabel, isAttachmentBond, Atom as Atom$2, findStereoAtoms, RxnArrowMode, SimpleObjectMode, emitEventRequestIsFinished, SGroup as SGroup$1, Pile, getStereoAtomsMap, identifyStructFormat, SupportedFormat, ChemicalMimeType, RenderStruct, Struct, FunctionalGroupsProvider, SaltsAndSolventsProvider, KetcherAsyncEvents, ElementColor, Vec2, fromMultipleMove, scrollByVector, FunctionalGroup, Scale, fromSgroupDeletion, fromFragmentDeletion, mergeMapOfItemsToSet, vectorUtils, fromBondAddition, Action, fromAtomAddition, fromAtomsAttrs, checkOverlapping, fromSeveralSgroupAddition, expandSGroupWithMultipleAttachmentPoint, SgContexts, fromSgroupAction, fromItemsFuse, ReBond, setExpandSGroup, fromBondsAttrs, OperationType, ReStruct, fromSimpleObjectResizing, fromArrowResizing, getItemsToFuse, getHoverToFuse, fromTextDeletion, fromTextUpdating, isCloseToEdgeOfCanvas, isCloseToEdgeOfScreen, getDirections, shiftAndExtendCanvasByVector, formatProperties, ketcherProvider, getStructure, Fragment as Fragment$1, fromRGroupAttachmentPointUpdate, fromOneBondDeletion, bondChangingAction, fromChain, fromStereoFlagUpdate, fromOneAtomDeletion, fromArrowDeletion, fromPlusDeletion, fromSimpleObjectDeletion, fromRGroupAttachmentPointDeletion, fromPaste, fromTemplateOnAtom, RGroup as RGroup$2, fromRGroupFragment, fromUpdateIfThen, fromRGroupAttrs, fromArrowAddition, fromPlusAddition, fromRotate, fromFlip, fromSimpleObjectAddition, fromTemplateOnBondAction, fromTemplateOnCanvas, fromTextCreation, fromHighlightCreate, fromHighlightClear, fromNewCanvas, Render, fromDescriptorsAlign, atomGetAttr, getPropertiesByFormat, StereoFlag, getPropertiesByImgFormat, b64toBlob, Generics, TextCommand, DefaultStructServiceOptions } from 'ketcher-core';
28
28
  import * as React from 'react';
29
29
  import React__default, { createRef, Component, useRef, useEffect, useState, useMemo, createElement, forwardRef, useCallback, useLayoutEffect, Fragment as Fragment$2, PureComponent, lazy, Suspense } from 'react';
30
30
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
@@ -297,20 +297,76 @@ var ClipArea = function (_Component) {
297
297
  mousedown: function mousedown(event) {
298
298
  if (event.shiftKey && !isActiveElement(event.target)) event.preventDefault();
299
299
  },
300
- copy: function copy(event) {
301
- if (_this2.props.focused() && _this2.props.onCopy) {
302
- var data = _this2.props.onCopy();
303
- if (data) _copy(event.clipboardData, data);
304
- event.preventDefault();
300
+ copy: function () {
301
+ var _copy2 = _asyncToGenerator( _regeneratorRuntime.mark(function _callee(event) {
302
+ var data;
303
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
304
+ while (1) {
305
+ switch (_context.prev = _context.next) {
306
+ case 0:
307
+ if (!(_this2.props.focused() && _this2.props.onCopy)) {
308
+ _context.next = 8;
309
+ break;
310
+ }
311
+ _context.next = 3;
312
+ return _this2.props.onCopy();
313
+ case 3:
314
+ data = _context.sent;
315
+ if (!data) {
316
+ _context.next = 7;
317
+ break;
318
+ }
319
+ _context.next = 7;
320
+ return _copy(data);
321
+ case 7:
322
+ event.preventDefault();
323
+ case 8:
324
+ case "end":
325
+ return _context.stop();
326
+ }
327
+ }
328
+ }, _callee);
329
+ }));
330
+ function copy(_x) {
331
+ return _copy2.apply(this, arguments);
305
332
  }
306
- },
307
- cut: function cut(event) {
308
- if (_this2.props.focused() && _this2.props.onCut) {
309
- var data = _this2.props.onCut();
310
- if (data) _copy(event.clipboardData, data);
311
- event.preventDefault();
333
+ return copy;
334
+ }(),
335
+ cut: function () {
336
+ var _cut = _asyncToGenerator( _regeneratorRuntime.mark(function _callee2(event) {
337
+ var data;
338
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
339
+ while (1) {
340
+ switch (_context2.prev = _context2.next) {
341
+ case 0:
342
+ if (!(_this2.props.focused() && _this2.props.onCut)) {
343
+ _context2.next = 8;
344
+ break;
345
+ }
346
+ _context2.next = 3;
347
+ return _this2.props.onCut();
348
+ case 3:
349
+ data = _context2.sent;
350
+ if (!data) {
351
+ _context2.next = 7;
352
+ break;
353
+ }
354
+ _context2.next = 7;
355
+ return _copy(data);
356
+ case 7:
357
+ event.preventDefault();
358
+ case 8:
359
+ case "end":
360
+ return _context2.stop();
361
+ }
362
+ }
363
+ }, _callee2);
364
+ }));
365
+ function cut(_x2) {
366
+ return _cut.apply(this, arguments);
312
367
  }
313
- },
368
+ return cut;
369
+ }(),
314
370
  paste: function paste(event) {
315
371
  if (_this2.props.focused() && _this2.props.onPaste) {
316
372
  var data = _paste(event.clipboardData, _this2.props.formats);
@@ -359,20 +415,32 @@ function autoselect(cliparea) {
359
415
  cliparea.value = ' ';
360
416
  cliparea.select();
361
417
  }
362
- function _copy(cb, data) {
363
- if (!cb && ieCb) {
364
- ieCb.setData('text', data['text/plain']);
365
- } else {
366
- var curFmt = null;
367
- cb.setData('text/plain', data['text/plain']);
368
- try {
369
- Object.keys(data).forEach(function (fmt) {
370
- curFmt = fmt;
371
- cb.setData(fmt, data[fmt]);
372
- });
373
- } catch (ex) {
374
- }
375
- }
418
+ function _copy(_x3) {
419
+ return _copy3.apply(this, arguments);
420
+ }
421
+ function _copy3() {
422
+ _copy3 = _asyncToGenerator( _regeneratorRuntime.mark(function _callee3(data) {
423
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
424
+ while (1) {
425
+ switch (_context3.prev = _context3.next) {
426
+ case 0:
427
+ _context3.prev = 0;
428
+ _context3.next = 3;
429
+ return navigator.clipboard.writeText(data['text/plain']);
430
+ case 3:
431
+ _context3.next = 8;
432
+ break;
433
+ case 5:
434
+ _context3.prev = 5;
435
+ _context3.t0 = _context3["catch"](0);
436
+ case 8:
437
+ case "end":
438
+ return _context3.stop();
439
+ }
440
+ }
441
+ }, _callee3, null, [[0, 5]]);
442
+ }));
443
+ return _copy3.apply(this, arguments);
376
444
  }
377
445
  function _paste(cb, formats) {
378
446
  var data = {};
@@ -3201,7 +3269,7 @@ var zoom = {
3201
3269
 
3202
3270
  var openHelpLink = function openHelpLink() {
3203
3271
  var _window$open;
3204
- return (_window$open = window.open("https://github.com/epam/ketcher/blob/".concat("v2.15.0-rc.1\n", "/documentation/help.md#ketcher-overview"))) === null || _window$open === void 0 ? void 0 : _window$open.focus();
3272
+ return (_window$open = window.open("https://github.com/epam/ketcher/blob/".concat("v2.15.0-rc.2\n", "/documentation/help.md#ketcher-overview"))) === null || _window$open === void 0 ? void 0 : _window$open.focus();
3205
3273
  };
3206
3274
  var help = {
3207
3275
  help: {
@@ -16992,21 +17060,53 @@ function initClipboard(dispatch) {
16992
17060
  return !state.modal;
16993
17061
  },
16994
17062
  onCut: function onCut() {
16995
- var state = global.currentState;
16996
- var editor = state.editor;
16997
- var data = clipData(editor);
16998
- if (data) debAction({
16999
- tool: 'eraser',
17000
- opts: 1
17001
- });else editor.selection(null);
17002
- return data;
17063
+ return _asyncToGenerator( _regeneratorRuntime.mark(function _callee() {
17064
+ var state, editor, data;
17065
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
17066
+ while (1) {
17067
+ switch (_context.prev = _context.next) {
17068
+ case 0:
17069
+ state = global.currentState;
17070
+ editor = state.editor;
17071
+ _context.next = 4;
17072
+ return clipData(editor);
17073
+ case 4:
17074
+ data = _context.sent;
17075
+ if (data) debAction({
17076
+ tool: 'eraser',
17077
+ opts: 1
17078
+ });else editor.selection(null);
17079
+ return _context.abrupt("return", data);
17080
+ case 7:
17081
+ case "end":
17082
+ return _context.stop();
17083
+ }
17084
+ }
17085
+ }, _callee);
17086
+ }))();
17003
17087
  },
17004
17088
  onCopy: function onCopy() {
17005
- var state = global.currentState;
17006
- var editor = state.editor;
17007
- var data = clipData(editor);
17008
- editor.selection(null);
17009
- return data;
17089
+ return _asyncToGenerator( _regeneratorRuntime.mark(function _callee2() {
17090
+ var state, editor, data;
17091
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
17092
+ while (1) {
17093
+ switch (_context2.prev = _context2.next) {
17094
+ case 0:
17095
+ state = global.currentState;
17096
+ editor = state.editor;
17097
+ _context2.next = 4;
17098
+ return clipData(editor);
17099
+ case 4:
17100
+ data = _context2.sent;
17101
+ editor.selection(null);
17102
+ return _context2.abrupt("return", data);
17103
+ case 7:
17104
+ case "end":
17105
+ return _context2.stop();
17106
+ }
17107
+ }
17108
+ }, _callee2);
17109
+ }))();
17010
17110
  },
17011
17111
  onPaste: function onPaste(data) {
17012
17112
  var structStr = data[ChemicalMimeType.KET] || data[ChemicalMimeType.Mol] || data[ChemicalMimeType.Rxn] || data['text/plain'];
@@ -17017,30 +17117,61 @@ function initClipboard(dispatch) {
17017
17117
  }
17018
17118
  };
17019
17119
  }
17020
- function clipData(editor) {
17021
- var res = {};
17022
- var struct = editor.structSelected();
17023
- var errorHandler = editor.errorHandler;
17024
- if (struct.isBlank()) return null;
17025
- var simpleObjectOrText = Boolean(struct.simpleObjects.size || struct.texts.size);
17026
- if (simpleObjectOrText && isIE) {
17027
- errorHandler('The structure you are trying to copy contains Simple object or/and Text object.' + 'To copy Simple object or Text object in Internet Explorer try "Copy as KET" button');
17028
- return null;
17029
- }
17030
- var molSerializer = new MolSerializer();
17031
- try {
17032
- var serializer = new KetSerializer();
17033
- var ket = serializer.serialize(struct);
17034
- res[ChemicalMimeType.KET] = ket;
17035
- var type = struct.isReaction ? ChemicalMimeType.Mol : ChemicalMimeType.Rxn;
17036
- var data = molSerializer.serialize(struct);
17037
- res['text/plain'] = data;
17038
- res[type] = data;
17039
- return res;
17040
- } catch (e) {
17041
- errorHandler(e.message);
17042
- }
17043
- return null;
17120
+ function clipData(_x) {
17121
+ return _clipData.apply(this, arguments);
17122
+ }
17123
+ function _clipData() {
17124
+ _clipData = _asyncToGenerator( _regeneratorRuntime.mark(function _callee3(editor) {
17125
+ var res, struct, errorHandler, simpleObjectOrText, serializer, ket, ketcherInstance, data, type;
17126
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
17127
+ while (1) {
17128
+ switch (_context3.prev = _context3.next) {
17129
+ case 0:
17130
+ res = {};
17131
+ struct = editor.structSelected();
17132
+ errorHandler = editor.errorHandler;
17133
+ if (!struct.isBlank()) {
17134
+ _context3.next = 5;
17135
+ break;
17136
+ }
17137
+ return _context3.abrupt("return", null);
17138
+ case 5:
17139
+ simpleObjectOrText = Boolean(struct.simpleObjects.size || struct.texts.size);
17140
+ if (!(simpleObjectOrText && isIE && errorHandler)) {
17141
+ _context3.next = 9;
17142
+ break;
17143
+ }
17144
+ errorHandler('The structure you are trying to copy contains Simple object or/and Text object.' + 'To copy Simple object or Text object in Internet Explorer try "Copy as KET" button');
17145
+ return _context3.abrupt("return", null);
17146
+ case 9:
17147
+ _context3.prev = 9;
17148
+ serializer = new KetSerializer();
17149
+ ket = serializer.serialize(struct);
17150
+ ketcherInstance = ketcherProvider.getKetcher();
17151
+ _context3.next = 15;
17152
+ return getStructure(SupportedFormat.molAuto,
17153
+ ketcherInstance.formatterFactory, struct);
17154
+ case 15:
17155
+ data = _context3.sent;
17156
+ res[ChemicalMimeType.KET] = ket;
17157
+ type = struct.isReaction ? ChemicalMimeType.Mol : ChemicalMimeType.Rxn;
17158
+ res['text/plain'] = data;
17159
+ res[type] = data;
17160
+ return _context3.abrupt("return", res);
17161
+ case 23:
17162
+ _context3.prev = 23;
17163
+ _context3.t0 = _context3["catch"](9);
17164
+ errorHandler && errorHandler(_context3.t0.message);
17165
+ case 26:
17166
+ return _context3.abrupt("return", null);
17167
+ case 27:
17168
+ case "end":
17169
+ return _context3.stop();
17170
+ }
17171
+ }
17172
+ }, _callee3, null, [[9, 23]]);
17173
+ }));
17174
+ return _clipData.apply(this, arguments);
17044
17175
  }
17045
17176
 
17046
17177
  var AppClipArea = connect(null, function (dispatch) {
@@ -22527,35 +22658,45 @@ var useDelete$1 = function useDelete() {
22527
22658
  return handler;
22528
22659
  };
22529
22660
 
22661
+ var getAtomIdByProps = function getAtomIdByProps(props, ketcher) {
22662
+ var _props$atomIds, _props$rgroupAttachme;
22663
+ var editor = ketcher.editor;
22664
+ var restruct = editor.render.ctab;
22665
+ var atomId = props === null || props === void 0 ? void 0 : (_props$atomIds = props.atomIds) === null || _props$atomIds === void 0 ? void 0 : _props$atomIds[0];
22666
+ if (atomId != null) {
22667
+ return atomId;
22668
+ }
22669
+ var attachmentPointId = props === null || props === void 0 ? void 0 : (_props$rgroupAttachme = props.rgroupAttachmentPoints) === null || _props$rgroupAttachme === void 0 ? void 0 : _props$rgroupAttachme[0];
22670
+ assert_1(attachmentPointId != null);
22671
+ var attachmentPoint = restruct.molecule.rgroupAttachmentPoints.get(attachmentPointId);
22672
+ assert_1(attachmentPoint != null);
22673
+ return attachmentPoint.atomId;
22674
+ };
22530
22675
  var useRGroupAttachmentPointEdit = function useRGroupAttachmentPointEdit() {
22531
22676
  var _useAppContext = useAppContext(),
22532
22677
  getKetcherInstance = _useAppContext.getKetcherInstance;
22533
22678
  var handler = useCallback(function (_ref) {
22534
- var _props$atomIds;
22535
22679
  var props = _ref.props;
22536
- var editor = getKetcherInstance().editor;
22537
- var restruct = editor.render.ctab;
22538
- var atomId = props === null || props === void 0 ? void 0 : (_props$atomIds = props.atomIds) === null || _props$atomIds === void 0 ? void 0 : _props$atomIds[0];
22539
- assert_1(atomId != null);
22680
+ var ketcher = getKetcherInstance();
22681
+ var restruct = ketcher.editor.render.ctab;
22682
+ var atomId = getAtomIdByProps(props, ketcher);
22540
22683
  var atom = restruct.molecule.atoms.get(atomId);
22541
22684
  assert_1(atom != null);
22542
- editRGroupAttachmentPoint(editor, atom, atomId);
22685
+ editRGroupAttachmentPoint(ketcher.editor, atom, atomId);
22543
22686
  }, [getKetcherInstance]);
22544
22687
  var disabled = useCallback(function (_ref2) {
22545
- var _props$atomIds2;
22546
22688
  var props = _ref2.props;
22547
- var editor = getKetcherInstance().editor;
22548
- var restruct = editor.render.ctab;
22549
- var atomId = props === null || props === void 0 ? void 0 : (_props$atomIds2 = props.atomIds) === null || _props$atomIds2 === void 0 ? void 0 : _props$atomIds2[0];
22550
- assert_1(atomId != null);
22689
+ var ketcher = getKetcherInstance();
22690
+ var restruct = ketcher.editor.render.ctab;
22691
+ var atomId = getAtomIdByProps(props, ketcher);
22551
22692
  var atom = restruct.molecule.atoms.get(atomId);
22552
22693
  assert_1(atom != null);
22553
22694
  return atom.isRGroupAttachmentPointEditDisabled;
22554
22695
  }, [getKetcherInstance]);
22555
22696
  var hidden = useCallback(function (_ref3) {
22556
- var _props$atomIds3;
22697
+ var _props$atomIds2;
22557
22698
  var props = _ref3.props;
22558
- var atomLength = (props === null || props === void 0 ? void 0 : (_props$atomIds3 = props.atomIds) === null || _props$atomIds3 === void 0 ? void 0 : _props$atomIds3.length) || 0;
22699
+ var atomLength = (props === null || props === void 0 ? void 0 : (_props$atomIds2 = props.atomIds) === null || _props$atomIds2 === void 0 ? void 0 : _props$atomIds2.length) || 0;
22559
22700
  return atomLength > 1;
22560
22701
  }, []);
22561
22702
  return [handler, disabled, hidden];
@@ -30624,8 +30765,8 @@ var KetcherBuilder = function () {
30624
30765
  initApp(element, appRoot, staticResourcesUrl, {
30625
30766
  buttons: buttons || {},
30626
30767
  errorHandler: errorHandler || null,
30627
- version: "2.15.0-rc.1" ,
30628
- buildDate: "2023-09-04T11:49:56" ,
30768
+ version: "2.15.0-rc.3" ,
30769
+ buildDate: "2023-10-06T10:46:54" ,
30629
30770
  buildNumber: ''
30630
30771
  }, structService, resolve);
30631
30772
  });
@@ -30666,6 +30807,7 @@ var KetcherBuilder = function () {
30666
30807
  if (initialMol) {
30667
30808
  ketcher.setMolecule(initialMol);
30668
30809
  }
30810
+ ketcherProvider.setKetcherInstance(ketcher);
30669
30811
  return ketcher;
30670
30812
  }
30671
30813
  }]);