pdbe-molstar 3.7.0 → 3.7.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,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Layout = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const file_1 = require("molstar/lib/mol-plugin-state/actions/file");
6
+ const base_1 = require("molstar/lib/mol-plugin-ui/base");
7
+ const use_behavior_1 = require("molstar/lib/mol-plugin-ui/hooks/use-behavior");
8
+ const left_panel_1 = require("molstar/lib/mol-plugin-ui/left-panel");
9
+ const plugin_1 = require("molstar/lib/mol-plugin-ui/plugin");
10
+ const sequence_1 = require("molstar/lib/mol-plugin-ui/sequence");
11
+ const task_1 = require("molstar/lib/mol-plugin-ui/task");
12
+ const commands_1 = require("molstar/lib/mol-plugin/commands");
13
+ const assets_1 = require("molstar/lib/mol-util/assets");
14
+ const rxjs_1 = require("rxjs");
15
+ /** Copy of `Layout` in molstar/src/mol-plugin-ui/plugin.tsx, TODO export from core Molstar and remove here */
16
+ class Layout extends base_1.PluginUIComponent {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.onDrop = (ev) => {
20
+ ev.preventDefault();
21
+ const files = [];
22
+ if (ev.dataTransfer.items) {
23
+ // Use DataTransferItemList interface to access the file(s)
24
+ for (let i = 0; i < ev.dataTransfer.items.length; i++) { // eslint-disable-line @typescript-eslint/prefer-for-of
25
+ if (ev.dataTransfer.items[i].kind !== 'file')
26
+ continue;
27
+ const file = ev.dataTransfer.items[i].getAsFile();
28
+ if (file)
29
+ files.push(file);
30
+ }
31
+ }
32
+ else {
33
+ for (let i = 0; i < ev.dataTransfer.files.length; i++) { // eslint-disable-line @typescript-eslint/prefer-for-of
34
+ const file = ev.dataTransfer.files[i];
35
+ if (file)
36
+ files.push(file);
37
+ }
38
+ }
39
+ const sessions = files.filter(f => {
40
+ const fn = f.name.toLowerCase();
41
+ return fn.endsWith('.molx') || fn.endsWith('.molj');
42
+ });
43
+ if (sessions.length > 0) {
44
+ commands_1.PluginCommands.State.Snapshots.OpenFile(this.plugin, { file: sessions[0] });
45
+ }
46
+ else {
47
+ this.plugin.runTask(this.plugin.state.data.applyAction(file_1.OpenFiles, {
48
+ files: files.map(f => assets_1.Asset.File(f)),
49
+ format: { name: 'auto', params: {} },
50
+ visuals: true,
51
+ }));
52
+ }
53
+ };
54
+ this.onDragOver = (ev) => {
55
+ ev.preventDefault();
56
+ };
57
+ this.showDragOverlay = new rxjs_1.BehaviorSubject(false);
58
+ this.onDragEnter = (ev) => {
59
+ let hasFile = false;
60
+ if (ev.dataTransfer.items && ev.dataTransfer.items.length > 0) {
61
+ for (let i = 0; i < ev.dataTransfer.items.length; i++) { // eslint-disable-line @typescript-eslint/prefer-for-of
62
+ if (ev.dataTransfer.items[i].kind !== 'file')
63
+ continue;
64
+ hasFile = true;
65
+ break;
66
+ }
67
+ }
68
+ else {
69
+ for (let i = 0; i < ev.dataTransfer.types.length; i++) { // eslint-disable-line @typescript-eslint/prefer-for-of
70
+ if (ev.dataTransfer.types[i] !== 'Files')
71
+ continue;
72
+ hasFile = true;
73
+ break;
74
+ }
75
+ }
76
+ if (hasFile) {
77
+ this.showDragOverlay.next(true);
78
+ }
79
+ };
80
+ }
81
+ componentDidMount() {
82
+ this.subscribe(this.plugin.layout.events.updated, () => this.forceUpdate());
83
+ }
84
+ region(kind, Element) {
85
+ return (0, jsx_runtime_1.jsx)("div", { className: `msp-layout-region msp-layout-${kind}`, children: (0, jsx_runtime_1.jsx)("div", { className: 'msp-layout-static', children: Element ? (0, jsx_runtime_1.jsx)(Element, {}) : null }) });
86
+ }
87
+ get layoutVisibilityClassName() {
88
+ var _a, _b;
89
+ const layout = this.plugin.layout.state;
90
+ const controls = (_b = (_a = this.plugin.spec.components) === null || _a === void 0 ? void 0 : _a.controls) !== null && _b !== void 0 ? _b : {};
91
+ const classList = [];
92
+ if (controls.top === 'none' || !layout.showControls || layout.regionState.top === 'hidden') {
93
+ classList.push('msp-layout-hide-top');
94
+ }
95
+ if (controls.left === 'none' || !layout.showControls || layout.regionState.left === 'hidden') {
96
+ classList.push('msp-layout-hide-left');
97
+ }
98
+ else if (layout.regionState.left === 'collapsed') {
99
+ classList.push('msp-layout-collapse-left');
100
+ }
101
+ if (controls.right === 'none' || !layout.showControls || layout.regionState.right === 'hidden') {
102
+ classList.push('msp-layout-hide-right');
103
+ }
104
+ if (controls.bottom === 'none' || !layout.showControls || layout.regionState.bottom === 'hidden') {
105
+ classList.push('msp-layout-hide-bottom');
106
+ }
107
+ return classList.join(' ');
108
+ }
109
+ get layoutClassName() {
110
+ const layout = this.plugin.layout.state;
111
+ const classList = ['msp-plugin-content'];
112
+ if (layout.isExpanded) {
113
+ classList.push('msp-layout-expanded');
114
+ }
115
+ else {
116
+ classList.push('msp-layout-standard', `msp-layout-standard-${layout.controlsDisplay}`);
117
+ }
118
+ return classList.join(' ');
119
+ }
120
+ render() {
121
+ var _a, _b, _c, _d, _e, _f, _g;
122
+ const layout = this.plugin.layout.state;
123
+ const controls = ((_a = this.plugin.spec.components) === null || _a === void 0 ? void 0 : _a.controls) || {};
124
+ const viewport = ((_c = (_b = this.plugin.spec.components) === null || _b === void 0 ? void 0 : _b.viewport) === null || _c === void 0 ? void 0 : _c.view) || plugin_1.DefaultViewport;
125
+ const sequenceView = ((_e = (_d = this.plugin.spec.components) === null || _d === void 0 ? void 0 : _d.sequenceViewer) === null || _e === void 0 ? void 0 : _e.view) || sequence_1.SequenceView;
126
+ return (0, jsx_runtime_1.jsx)("div", { className: 'msp-plugin', children: (0, jsx_runtime_1.jsxs)("div", { className: this.layoutClassName, onDragEnter: this.onDragEnter, children: [(0, jsx_runtime_1.jsxs)("div", { className: this.layoutVisibilityClassName, children: [this.region('main', viewport), layout.showControls && controls.top !== 'none' && this.region('top', controls.top || sequenceView), layout.showControls && controls.left !== 'none' && this.region('left', controls.left || left_panel_1.LeftPanelControls), layout.showControls && controls.right !== 'none' && this.region('right', controls.right || plugin_1.ControlsWrapper), layout.showControls && controls.bottom !== 'none' && this.region('bottom', controls.bottom || plugin_1.Log)] }), !((_f = this.plugin.spec.components) === null || _f === void 0 ? void 0 : _f.hideTaskOverlay) && (0, jsx_runtime_1.jsx)(task_1.OverlayTaskProgress, {}), !((_g = this.plugin.spec.components) === null || _g === void 0 ? void 0 : _g.disableDragOverlay) && (0, jsx_runtime_1.jsx)(DragOverlay, { plugin: this.plugin, showDragOverlay: this.showDragOverlay })] }) });
127
+ }
128
+ }
129
+ exports.Layout = Layout;
130
+ function dropFiles(ev, plugin, showDragOverlay) {
131
+ ev.preventDefault();
132
+ ev.stopPropagation();
133
+ showDragOverlay.next(false);
134
+ const files = [];
135
+ if (ev.dataTransfer.items) {
136
+ // Use DataTransferItemList interface to access the file(s)
137
+ for (let i = 0; i < ev.dataTransfer.items.length; i++) { // eslint-disable-line @typescript-eslint/prefer-for-of
138
+ if (ev.dataTransfer.items[i].kind !== 'file')
139
+ continue;
140
+ const file = ev.dataTransfer.items[i].getAsFile();
141
+ if (file)
142
+ files.push(file);
143
+ }
144
+ }
145
+ else {
146
+ for (let i = 0; i < ev.dataTransfer.files.length; i++) { // eslint-disable-line @typescript-eslint/prefer-for-of
147
+ const file = ev.dataTransfer.files[i];
148
+ if (file)
149
+ files.push(file);
150
+ }
151
+ }
152
+ plugin.managers.dragAndDrop.handle(files);
153
+ }
154
+ function DragOverlay({ plugin, showDragOverlay }) {
155
+ const show = (0, use_behavior_1.useBehavior)(showDragOverlay);
156
+ const preventDrag = (e) => {
157
+ e.dataTransfer.dropEffect = 'copy';
158
+ e.preventDefault();
159
+ e.stopPropagation();
160
+ };
161
+ return (0, jsx_runtime_1.jsx)("div", { className: 'msp-drag-drop-overlay', style: { display: show ? 'flex' : 'none' }, onDragEnter: preventDrag, onDragOver: preventDrag, onDragLeave: () => showDragOverlay.next(false), onDrop: e => dropFiles(e, plugin, showDragOverlay), children: "Load File(s)" });
162
+ }
@@ -0,0 +1,5 @@
1
+ import { Layout } from './_layout';
2
+ export declare class FullLayoutNoControlsUnlessExpanded extends Layout {
3
+ componentDidMount(): void;
4
+ get layoutVisibilityClassName(): string;
5
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FullLayoutNoControlsUnlessExpanded = void 0;
4
+ const config_1 = require("molstar/lib/mol-plugin/config");
5
+ const plugin_custom_state_1 = require("../plugin-custom-state");
6
+ const _layout_1 = require("./_layout");
7
+ class FullLayoutNoControlsUnlessExpanded extends _layout_1.Layout {
8
+ componentDidMount() {
9
+ super.componentDidMount();
10
+ // Hide Toggle Controls button unless expanded:
11
+ this.subscribe(this.plugin.layout.events.updated, () => {
12
+ var _a, _b;
13
+ const isExpanded = this.plugin.layout.state.isExpanded;
14
+ const hideControlToggle = (_b = (_a = (0, plugin_custom_state_1.PluginCustomState)(this.plugin).initParams) === null || _a === void 0 ? void 0 : _a.hideCanvasControls.includes('controlToggle')) !== null && _b !== void 0 ? _b : false;
15
+ this.plugin.config.set(config_1.PluginConfig.Viewport.ShowControls, isExpanded && !hideControlToggle);
16
+ });
17
+ }
18
+ get layoutVisibilityClassName() {
19
+ const classes = super.layoutVisibilityClassName.split(' ');
20
+ const state = this.plugin.layout.state;
21
+ if (!state.isExpanded) {
22
+ if (!classes.includes('msp-layout-hide-top'))
23
+ classes.push('msp-layout-hide-top');
24
+ if (!classes.includes('msp-layout-hide-bottom'))
25
+ classes.push('msp-layout-hide-bottom');
26
+ if (!classes.includes('msp-layout-hide-left'))
27
+ classes.push('msp-layout-hide-left');
28
+ if (!classes.includes('msp-layout-hide-right'))
29
+ classes.push('msp-layout-hide-right');
30
+ }
31
+ return classes.join(' ');
32
+ }
33
+ }
34
+ exports.FullLayoutNoControlsUnlessExpanded = FullLayoutNoControlsUnlessExpanded;
@@ -1,5 +1,4 @@
1
1
  import { ViewportControls } from 'molstar/lib/mol-plugin-ui/viewport';
2
2
  export declare class PDBeViewportControls extends ViewportControls {
3
- private isBlack;
4
3
  render(): import("react/jsx-runtime").JSX.Element;
5
4
  }
@@ -2,31 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PDBeViewportControls = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const common_1 = require("molstar/lib/mol-plugin-ui/controls/common");
5
6
  const viewport_1 = require("molstar/lib/mol-plugin-ui/viewport");
6
- const names_1 = require("molstar/lib/mol-util/color/names");
7
- const helpers_1 = require("../helpers");
8
7
  const plugin_custom_state_1 = require("../plugin-custom-state");
9
8
  class PDBeViewportControls extends viewport_1.ViewportControls {
10
- isBlack() {
11
- var _a;
12
- const bgColor = (_a = (0, plugin_custom_state_1.PluginCustomState)(this.plugin).initParams) === null || _a === void 0 ? void 0 : _a.bgColor;
13
- return bgColor !== undefined && (0, helpers_1.normalizeColor)(bgColor) === names_1.ColorNames.black;
14
- }
15
9
  render() {
16
10
  const initParams = (0, plugin_custom_state_1.PluginCustomState)(this.plugin).initParams;
17
11
  const showPDBeLink = (initParams === null || initParams === void 0 ? void 0 : initParams.moleculeId) && (initParams === null || initParams === void 0 ? void 0 : initParams.pdbeLink) && !(initParams === null || initParams === void 0 ? void 0 : initParams.superposition);
18
- const pdbeLinkColor = this.isBlack() ? '#fff' : '#555';
19
- const pdbeLink = {
20
- containerStyle: { position: 'absolute', right: '10px', top: '10px', padding: '6px', paddingRight: '3px', paddingLeft: '18px' },
21
- bgStyle: { position: 'absolute', height: '32px', width: '54px', marginLeft: '-33px' },
22
- style: { display: 'inline-block', fontSize: '14px', color: pdbeLinkColor, borderBottom: 'none', cursor: 'pointer', textDecoration: 'none', position: 'absolute', right: '5px' },
23
- pdbeImg: {
24
- src: 'https://www.ebi.ac.uk/pdbe/entry/static/images/logos/PDBe/logo_T_64.png',
25
- alt: 'PDBe logo',
26
- style: { height: '12px', width: '12px', border: 0, position: 'absolute', margin: '4px 0 0 -13px' },
27
- },
28
- };
29
- return (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [showPDBeLink && (0, jsx_runtime_1.jsxs)("div", { className: 'msp-viewport-controls-buttons', style: pdbeLink.containerStyle, children: [(0, jsx_runtime_1.jsx)("div", { className: 'msp-semi-transparent-background', style: pdbeLink.bgStyle }), (0, jsx_runtime_1.jsxs)("a", { className: 'msp-pdbe-link', style: pdbeLink.style, target: "_blank", href: `https://pdbe.org/${initParams.moleculeId}`, children: [(0, jsx_runtime_1.jsx)("img", { src: pdbeLink.pdbeImg.src, alt: pdbeLink.pdbeImg.alt, style: pdbeLink.pdbeImg.style }), initParams.moleculeId] })] }), (0, jsx_runtime_1.jsx)("div", { style: { position: 'absolute', top: showPDBeLink ? (32 + 4) : 0, right: 0 }, children: super.render() })] });
12
+ return (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [showPDBeLink &&
13
+ (0, jsx_runtime_1.jsx)("div", { className: 'msp-viewport-controls', children: (0, jsx_runtime_1.jsx)("div", { className: 'msp-viewport-controls-buttons', children: (0, jsx_runtime_1.jsxs)("div", { className: 'pdbemolstar-pdbe-link-box', children: [(0, jsx_runtime_1.jsx)("div", { className: 'msp-semi-transparent-background' }), (0, jsx_runtime_1.jsx)("a", { target: '_blank', href: `https://pdbe.org/${initParams.moleculeId}`, style: { textDecoration: 'none', color: 'initial' }, children: (0, jsx_runtime_1.jsxs)(common_1.Button, { className: 'msp-btn-link-toggle-on pdbemolstar-pdbe-link', title: 'Go to PDBe Pages', children: [(0, jsx_runtime_1.jsx)("img", { className: 'pdbemolstar-pdbe-logo', alt: 'PDBe logo', src: 'https://www.ebi.ac.uk/pdbe/entry/static/images/logos/PDBe/logo_T_64.png' }), initParams.moleculeId] }) })] }) }) }), (0, jsx_runtime_1.jsx)("div", { className: showPDBeLink ? 'pdbemolstar-viewport-controls-shifted' : 'pdbemolstar-viewport-controls-normal', children: super.render() })] });
30
14
  }
31
15
  }
32
16
  exports.PDBeViewportControls = PDBeViewportControls;
@@ -1,5 +1,6 @@
1
1
  import { ControlsWrapper, Log } from 'molstar/lib/mol-plugin-ui/plugin';
2
2
  import { SequenceView } from 'molstar/lib/mol-plugin-ui/sequence';
3
+ import { FullLayoutNoControlsUnlessExpanded } from '../layout-no-controls-unless-expanded';
3
4
  export declare const UIComponents: {
4
5
  /** Component containing 3D canvas, button in top left and top right corners, and tooltip box (center panel in default layout). Changes to fullscreen view by "Toggle Expanded Viewport" button, or "expanded" option. */
5
6
  readonly PDBeViewport: import("react").ComponentClass<{}, any>;
@@ -13,4 +14,6 @@ export declare const UIComponents: {
13
14
  readonly DefaultLeftPanelControls: import("react").ComponentClass<{}, any>;
14
15
  /** Component containing right panel controls (contents depend on PDBeMolstar init params (superposition/ligand/default view)) */
15
16
  readonly DefaultRightPanelControls: typeof ControlsWrapper;
17
+ /** Component containing only `PDBeViewport` when not in fullscreen view, but shows full UI layout when in fullscreen view. */
18
+ readonly FullLayoutNoControlsUnlessExpanded: typeof FullLayoutNoControlsUnlessExpanded;
16
19
  };
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UIComponents = void 0;
4
4
  const plugin_1 = require("molstar/lib/mol-plugin-ui/plugin");
5
5
  const sequence_1 = require("molstar/lib/mol-plugin-ui/sequence");
6
+ const layout_no_controls_unless_expanded_1 = require("../layout-no-controls-unless-expanded");
6
7
  const pdbe_left_panel_1 = require("../left-panel/pdbe-left-panel");
7
8
  const pdbe_viewport_1 = require("../pdbe-viewport");
8
9
  exports.UIComponents = {
@@ -18,5 +19,7 @@ exports.UIComponents = {
18
19
  DefaultLeftPanelControls: pdbe_left_panel_1.DefaultLeftPanelControls,
19
20
  /** Component containing right panel controls (contents depend on PDBeMolstar init params (superposition/ligand/default view)) */
20
21
  DefaultRightPanelControls: plugin_1.ControlsWrapper,
22
+ /** Component containing only `PDBeViewport` when not in fullscreen view, but shows full UI layout when in fullscreen view. */
23
+ FullLayoutNoControlsUnlessExpanded: layout_no_controls_unless_expanded_1.FullLayoutNoControlsUnlessExpanded,
21
24
  // TODO add all meaningful components,
22
25
  };
package/lib/viewer.d.ts CHANGED
@@ -232,6 +232,7 @@ export declare class PDBeMolstarPlugin {
232
232
  readonly PDBeLeftPanelControls: import("react").ComponentClass<{}, any>;
233
233
  readonly DefaultLeftPanelControls: import("react").ComponentClass<{}, any>;
234
234
  readonly DefaultRightPanelControls: typeof import("molstar/lib/mol-plugin-ui/plugin").ControlsWrapper;
235
+ readonly FullLayoutNoControlsUnlessExpanded: typeof import("./ui/layout-no-controls-unless-expanded").FullLayoutNoControlsUnlessExpanded;
235
236
  };
236
237
  static MAIN_STRUCTURE_ID: string;
237
238
  }
package/lib/viewer.js CHANGED
@@ -431,8 +431,6 @@ class PDBeMolstarPlugin {
431
431
  if (this.initParams.customData && this.initParams.customData.url && !this.initParams.customData.format)
432
432
  return false;
433
433
  (0, plugin_custom_state_1.PluginCustomState)(this.plugin).initParams = this.initParams;
434
- // Update layout
435
- commands_1.PluginCommands.Layout.Update(this.plugin, { state: (0, helpers_1.pluginLayoutStateFromInitParams)(this.initParams) });
436
434
  // Show/hide buttons in the viewport control panel
437
435
  this.plugin.config.set(config_1.PluginConfig.Viewport.ShowScreenshotControls, !this.initParams.hideCanvasControls.includes('screenshot'));
438
436
  this.plugin.config.set(config_1.PluginConfig.Viewport.ShowExpand, !this.initParams.hideCanvasControls.includes('expand'));
@@ -441,6 +439,8 @@ class PDBeMolstarPlugin {
441
439
  this.plugin.config.set(config_1.PluginConfig.Viewport.ShowSelectionMode, !this.initParams.hideCanvasControls.includes('selection'));
442
440
  this.plugin.config.set(config_1.PluginConfig.Viewport.ShowAnimation, !this.initParams.hideCanvasControls.includes('animation'));
443
441
  this.plugin.config.set(config_1.PluginConfig.Viewport.ShowTrajectoryControls, !this.initParams.hideCanvasControls.includes('trajectory'));
442
+ // Update layout
443
+ commands_1.PluginCommands.Layout.Update(this.plugin, { state: (0, helpers_1.pluginLayoutStateFromInitParams)(this.initParams) });
444
444
  // Set background colour
445
445
  if (this.initParams.bgColor || this.initParams.lighting) {
446
446
  yield this.canvas.applySettings({ color: this.initParams.bgColor, lighting: this.initParams.lighting });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdbe-molstar",
3
- "version": "3.7.0",
3
+ "version": "3.7.1",
4
4
  "description": "Molstar implementation for PDBe",
5
5
  "main": "index.js",
6
6
  "scripts": {