@datagrok/helm 2.3.1 → 2.3.2

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,198 @@
1
+ import * as ui from 'datagrok-api/ui';
2
+ import * as grok from 'datagrok-api/grok';
3
+ import * as DG from 'datagrok-api/dg';
4
+
5
+ import $ from 'cash-dom';
6
+ import {fromEvent, Unsubscribable} from 'rxjs';
7
+
8
+ import {IMonomerLib} from '@datagrok-libraries/bio/src/types/index';
9
+ import {IHelmHelper, IInputInitOptions} from '@datagrok-libraries/bio/src/helm/helm-helper';
10
+ import {HelmMol, IHelmWebEditor} from '@datagrok-libraries/bio/src/helm/types';
11
+
12
+ import {defaultErrorHandler} from '../utils/err-info';
13
+ import {getHoveredMonomerFromEditorMol} from '../utils/get-hovered';
14
+
15
+ import {_package, getMonomerLib} from '../package';
16
+
17
+
18
+ export class HelmInput extends DG.JsInputBase<HelmMol> {
19
+ /** Input type identifier (such as "Slider" for the slider input). See {@link InputType}. */
20
+ get inputType(): string {
21
+ return 'Macromolecule';
22
+ }
23
+
24
+ /** Data type this input can edit. See {@link DG.Type}. */
25
+ get dataType(): string {
26
+ return DG.TYPE.STRING;
27
+ }
28
+
29
+ getInput(): HTMLElement {
30
+ return this.viewerHost;
31
+ }
32
+
33
+ getValue(): HelmMol {
34
+ return this.viewer.editor.m;
35
+ }
36
+
37
+ setValue(value: HelmMol): void {
38
+ this.viewer.editor.setMol(value);
39
+ }
40
+
41
+ getStringValue(): string {
42
+ return this.viewer.editor.getHelm();
43
+ }
44
+
45
+ setStringValue(value: string): void {
46
+ this.viewer.editor.setHelm(value);
47
+ }
48
+
49
+ viewerHost: HTMLDivElement;
50
+ viewer: IHelmWebEditor;
51
+ helmString: string = '';
52
+ helmSelection: number[];
53
+
54
+ private subs: Unsubscribable[];
55
+
56
+ protected constructor(
57
+ private readonly helmHelper: IHelmHelper,
58
+ private readonly monomerLib: IMonomerLib,
59
+ name?: string,
60
+ private readonly logger = _package.logger,
61
+ ) {
62
+ super();
63
+
64
+ if (name) this.captionLabel.innerText = name;
65
+
66
+ this.viewerHost = ui.div([], {
67
+ classes: 'ui-input-editor',
68
+ style: {width: '100%', height: '100%', overflow: 'hidden'},
69
+ });
70
+ this.viewer = this.helmHelper.createHelmWebEditor(this.viewerHost);
71
+
72
+ this.subs = [];
73
+ this.subs.push(this.monomerLib.onChanged
74
+ .subscribe(() => this.viewer.editor.redraw()));
75
+ this.subs.push(fromEvent<MouseEvent>(this.viewer.host, 'mousemove')
76
+ .subscribe(this.viewerOnMouseMove.bind(this)));
77
+ this.subs.push(fromEvent<MouseEvent>(this.viewer.host, 'click')
78
+ .subscribe(this.viewerOnClick.bind(this)));
79
+
80
+ this.root.classList.add('ui-input-helm');
81
+ this.root.append(this.viewerHost);
82
+ }
83
+
84
+ protected toLog(): string {
85
+ return `Helm: HelmInput<#>`;
86
+ }
87
+
88
+ /** Inspired by {@link DG.MarkdownInput}, {@link ui._create} */
89
+ static create(
90
+ helmHelper: IHelmHelper, monomerLib: IMonomerLib, name?: string, options?: IInputInitOptions<HelmMol>
91
+ ): HelmInput {
92
+ const input = new HelmInput(helmHelper, monomerLib, name);
93
+ // TODO: Apply options
94
+ const value: HelmMol | string | undefined = options?.value;
95
+ if (value !== undefined) {
96
+ if (value instanceof String || typeof value === 'string')
97
+ input.stringValue = value as any as string;
98
+ else
99
+ input.value = value;
100
+ }
101
+
102
+ return input;
103
+ }
104
+
105
+ // static async init(host?: HTMLElement, cell?: DG.Cell): Promise<HelmInput> {
106
+ // const helmHelper = await getHelmHelper();
107
+ // const libHelper = await getMonomerLibHelper();
108
+ //
109
+ // const editor = helmHelper.createHelmWebEditor();
110
+ // editor.host.style.width = '270px';
111
+ // editor.host.style.height = '150px';
112
+ // editor.host.style.paddingLeft = '40px';
113
+ //
114
+ // cell = cell ?? grok.shell.tv.dataFrame.currentCell;
115
+ //
116
+ // if (cell.column.semType === DG.SEMTYPE.MACROMOLECULE && cell.column.tags[DG.TAGS.UNITS] === NOTATION.HELM)
117
+ // editor.editor.setHelm(cell.value);
118
+ // else
119
+ // editor.editor.setHelm(PT_HELM_EXAMPLE);
120
+ //
121
+ // return new HelmInput(helmHelper, editor, libHelper);
122
+ // }
123
+
124
+ setHelmString(helm: string): void {
125
+ this.helmString = helm;
126
+ this.viewer.editor.setHelm(helm);
127
+ this.helmSelection = [];
128
+ }
129
+
130
+ getDiv(): HTMLDivElement {
131
+ const title = ui.divText('Macromolecule', {style: {paddingTop: '43px', color: 'var(--grey-4)'}});
132
+
133
+ return ui.divH([title, this.viewer.host], {style: {paddingLeft: '48px'}});
134
+ }
135
+
136
+ // -- Handle events --
137
+
138
+ private viewerOnClick(_event: MouseEvent): void {
139
+ ui.tooltip.hide();
140
+
141
+ const webEditorHost = ui.div();
142
+ const webEditorApp = this.helmHelper.createWebEditorApp(webEditorHost, this.viewer.editor.getHelm());
143
+
144
+ const destroyEditorDialog = () => {
145
+ $(webEditorHost).empty();
146
+ };
147
+
148
+ // Edit the molecule and select monomers to enumerate
149
+ const dlg = ui.dialog({showHeader: false, showFooter: true})
150
+ .add(webEditorHost!)
151
+ .onOK(() => {
152
+ try {
153
+ const webEditorValue = webEditorApp!.canvas.getHelm(true)
154
+ .replace(/<\/span>/g, '').replace(/<span style='background:#bbf;'>/g, '');
155
+ this.viewer.editor.setHelm(webEditorValue);
156
+ this.helmString = webEditorValue;
157
+
158
+ const selection = webEditorApp!.canvas.helm.jsd.m.atoms;
159
+ this.helmSelection = [];
160
+ for (let i = 0; i < selection.length; i++) {
161
+ if (selection[i].selected)
162
+ this.helmSelection.push(i);
163
+
164
+ this.viewer.editor.m.atoms[i].highlighted = selection[i].selected;
165
+ }
166
+ this.viewer.editor.redraw();
167
+ } catch (err: any) {
168
+ defaultErrorHandler(err);
169
+ } finally {
170
+ destroyEditorDialog();
171
+ }
172
+ })
173
+ .onCancel(() => {
174
+ destroyEditorDialog();
175
+ })
176
+ .show({modal: true, fullScreen: true});
177
+ }
178
+
179
+ private viewerOnMouseMove(event: MouseEvent): void {
180
+ const logPrefix = `${this.toLog()}.viewerOnMouseMove()`;
181
+ const dpr = window.devicePixelRatio;
182
+
183
+ const argsX = event.offsetX;
184
+ const argsY = event.offsetY;
185
+ const mol = this.viewer.editor.m;
186
+ const seqMonomer = getHoveredMonomerFromEditorMol(argsX, argsY, mol, this.viewer.editor.div.clientHeight);
187
+ if (seqMonomer) {
188
+ const monomerLib = getMonomerLib();
189
+ const tooltipEl = monomerLib ? monomerLib.getTooltip(seqMonomer.polymerType, seqMonomer.symbol) :
190
+ ui.divText('Monomer library is not available');
191
+ ui.tooltip.show(tooltipEl, event.x + 16, event.y + 16);
192
+ } else {
193
+ // Tooltip for missing monomers
194
+ ui.tooltip.hide();
195
+ }
196
+ this.logger.debug(`${logPrefix}, x = ${event.x}, y = ${event.y}`);
197
+ }
198
+ }
package/webpack.config.js CHANGED
@@ -6,7 +6,8 @@ if (mode !== 'production')
6
6
  console.warn(`Building '${packageName}' in '${mode}' mode.`);
7
7
 
8
8
  module.exports = {
9
- ...(mode !== 'production' ? {} : {cache: {type: 'filesystem'}}),
9
+ //...(mode !== 'production' ? {} : {cache: {type: 'filesystem'}}),
10
+ cache: {type: 'filesystem'},
10
11
  mode: mode,
11
12
  entry: {
12
13
  package: './src/package.ts',
@@ -35,7 +36,7 @@ module.exports = {
35
36
  {test: /\.css$/, use: ['style-loader', 'css-loader'], exclude: [/node_modules/, /vendor/]},
36
37
  ],
37
38
  },
38
- devtool: mode !== 'production' ? 'inline-source-map' : 'source-map',
39
+ devtool: 'source-map',
39
40
  externals: {
40
41
  'datagrok-api/dg': 'DG',
41
42
  'datagrok-api/grok': 'grok',