@datagrok/helm 2.1.26 → 2.1.27

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@datagrok/helm",
3
3
  "friendlyName": "Helm",
4
- "version": "2.1.26",
4
+ "version": "2.1.27",
5
5
  "author": {
6
6
  "name": "Oleksandra Serhiienko",
7
7
  "email": "oserhiienko@datagrok.ai"
@@ -144,36 +144,6 @@ function getHoveredMonomerFallback(
144
144
  return hoveredSeqMonomer;
145
145
  }
146
146
 
147
- // patch window.dojox.gfx.svg.Text.prototype.getTextWidth hangs
148
- /** get the text width in pixels */
149
- // @ts-ignore
150
- window.dojox.gfx.svg.Text.prototype.getTextWidth = function() {
151
- const rawNode = this.rawNode;
152
- const oldParent = rawNode.parentNode;
153
- const _measurementNode = rawNode.cloneNode(true);
154
- _measurementNode.style.visibility = 'hidden';
155
-
156
- // solution to the "orphan issue" in FF
157
- let _width = 0;
158
- const _text = _measurementNode.firstChild.nodeValue;
159
- oldParent.appendChild(_measurementNode);
160
-
161
- // solution to the "orphan issue" in Opera
162
- // (nodeValue == "" hangs firefox)
163
- if (_text != '') {
164
- let watchdogCounter = 100;
165
- while (!_width && --watchdogCounter > 0) { // <-- hangs
166
- //Yang: work around svgweb bug 417 -- http://code.google.com/p/svgweb/issues/detail?id=417
167
- if (_measurementNode.getBBox)
168
- _width = parseInt(_measurementNode.getBBox().width);
169
- else
170
- _width = 68;
171
- }
172
- }
173
- oldParent.removeChild(_measurementNode);
174
- return _width;
175
- };
176
-
177
147
  /** Helm cell renderer in case of no missed monomer draws with JSDraw2.Editor (webeditor),
178
148
  * in case of missed monomers presented, draws linear sequences aligned in width per monomer.
179
149
  */
package/src/package.ts CHANGED
@@ -3,6 +3,8 @@ import * as grok from 'datagrok-api/grok';
3
3
  import * as ui from 'datagrok-api/ui';
4
4
  import * as DG from 'datagrok-api/dg';
5
5
 
6
+ import $ from 'cash-dom';
7
+
6
8
  import {errorToConsole} from '@datagrok-libraries/utils/src/to-console';
7
9
  import {NOTATION} from '@datagrok-libraries/bio/src/utils/macromolecule';
8
10
  import {GapSymbols, UnitsHandler} from '@datagrok-libraries/bio/src/utils/units-handler';
@@ -20,6 +22,38 @@ import {WebEditorMonomer, RGROUP_CAP_GROUP_NAME, RGROUP_LABEL, SMILES} from './c
20
22
 
21
23
  export const _package = new DG.Package();
22
24
 
25
+ function initHelmPatchDojo(): void {
26
+ // patch window.dojox.gfx.svg.Text.prototype.getTextWidth hangs
27
+ /** get the text width in pixels */
28
+ // @ts-ignore
29
+ window.dojox.gfx.svg.Text.prototype.getTextWidth = function() {
30
+ const rawNode = this.rawNode;
31
+ const oldParent = rawNode.parentNode;
32
+ const _measurementNode = rawNode.cloneNode(true);
33
+ _measurementNode.style.visibility = 'hidden';
34
+
35
+ // solution to the "orphan issue" in FF
36
+ let _width = 0;
37
+ const _text = _measurementNode.firstChild.nodeValue;
38
+ oldParent.appendChild(_measurementNode);
39
+
40
+ // solution to the "orphan issue" in Opera
41
+ // (nodeValue == "" hangs firefox)
42
+ if (_text != '') {
43
+ let watchdogCounter = 100;
44
+ while (!_width && --watchdogCounter > 0) { // <-- hangs
45
+ //Yang: work around svgweb bug 417 -- http://code.google.com/p/svgweb/issues/detail?id=417
46
+ if (_measurementNode.getBBox)
47
+ _width = parseInt(_measurementNode.getBBox().width);
48
+ else
49
+ _width = 68;
50
+ }
51
+ }
52
+ oldParent.removeChild(_measurementNode);
53
+ return _width;
54
+ };
55
+ }
56
+
23
57
  //tags: init
24
58
  export async function initHelm(): Promise<void> {
25
59
  //@ts-ignore
@@ -29,6 +63,8 @@ export async function initHelm(): Promise<void> {
29
63
  new Promise((resolve, reject) => {
30
64
  // @ts-ignore
31
65
  dojo.ready(function() { resolve(null); });
66
+ }).then(() => {
67
+ initHelmPatchDojo();
32
68
  }),
33
69
  grok.functions.call('Bio:getBioLib'),
34
70
  ])
@@ -107,7 +143,7 @@ function rewriteLibraries() {
107
143
  });
108
144
 
109
145
  // Obsolete
110
- const grid: DG.Grid = grok.shell.tv.grid;
146
+ const grid: DG.Grid = grok.shell.tv?.grid;
111
147
  if (grid) grid.invalidate();
112
148
  }
113
149
 
@@ -249,21 +285,22 @@ function getRS(smiles: string) {
249
285
  //input: column col {semType: Macromolecule}
250
286
  //output: column res
251
287
  export function getMolfiles(col: DG.Column): DG.Column {
252
- const grid = grok.shell.tv.grid;
253
- const parent = grid.root.parentElement!;
254
288
  const res = DG.Column.string('mols', col.length);
255
- const host = ui.div([]);
256
- parent.appendChild(host);
257
- const editor = new JSDraw2.Editor(host, {viewonly: true});
258
- host.style.width = '0px';
259
- host.style.height = '0px';
260
- res.init((i) => {
261
- editor.setHelm(col.get(i));
262
- const mol = editor.getMolfile();
263
- return mol;
264
- });
265
- parent.lastChild!.remove();
266
- return res;
289
+
290
+ const host = ui.div([], {style: {width: '0', height: '0'}});
291
+ document.documentElement.appendChild(host);
292
+ try {
293
+ const editor = new JSDraw2.Editor(host, {viewonly: true});
294
+ res.init((i) => {
295
+ editor.setHelm(col.get(i));
296
+ const mol = editor.getMolfile();
297
+ return mol;
298
+ });
299
+ return res;
300
+ } finally {
301
+ $(host).empty();
302
+ host.remove();
303
+ }
267
304
  }
268
305
 
269
306
  // -- Utils --
@@ -14,8 +14,8 @@ export function getPropertiesDict(seq: string, uh: UnitsHandler): {} {
14
14
  .replaceAll(/\{(\*\.)+/g, '{').replaceAll(/(\.\*)+}/g, '}');
15
15
 
16
16
  const host = ui.div([], {style: {width: '0', height: '0'}});
17
+ document.documentElement.appendChild(host);
17
18
  try {
18
- document.documentElement.appendChild(host);
19
19
  const editor = new JSDraw2.Editor(host, {viewonly: true});
20
20
  editor.setHelm(helmString2);
21
21