@vitessce/neuroglancer 3.6.18 → 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.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { N } from "./index-BNCfoEHv.js";
1
+ import { N } from "./index-w8xI9TWU.js";
2
2
  export {
3
3
  N as NeuroglancerSubscriber
4
4
  };
@@ -1,7 +1,7 @@
1
- export class Neuroglancer {
1
+ export class NeuroglancerComp {
2
2
  constructor(props: any);
3
3
  bundleRoot: any;
4
- viewerState: any;
4
+ cellColorMapping: any;
5
5
  justReceivedExternalUpdate: boolean;
6
6
  prevElement: any;
7
7
  prevClickHandler: ((event: any) => void) | null;
@@ -9,7 +9,9 @@ export class Neuroglancer {
9
9
  prevHoverHandler: (() => void) | null;
10
10
  onViewerStateChanged(nextState: any): void;
11
11
  onRef(viewerRef: any): void;
12
- UNSAFE_componentWillUpdate(prevProps: any): void;
12
+ latestOnSegmentClick: any;
13
+ latestOnSelectHoveredCoords: any;
14
+ componentDidUpdate(prevProps: any): void;
13
15
  render(): JSX.Element;
14
16
  }
15
17
  //# sourceMappingURL=Neuroglancer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Neuroglancer.d.ts","sourceRoot":"","sources":["../src/Neuroglancer.js"],"names":[],"mappings":"AA+DA;IACE,wBAeC;IAZC,gBAAgC;IAEhC,iBAAoC;IACpC,oCAAuC;IAEvC,iBAAuB;IACvB,gDAA4B;IAC5B,2BAAiC;IACjC,sCAA4B;IAkD9B,2CASC;IArDD,4BA0CC;IAaD,iDAQC;IAED,sBAqBC;CACF"}
1
+ {"version":3,"file":"Neuroglancer.d.ts","sourceRoot":"","sources":["../src/Neuroglancer.js"],"names":[],"mappings":"AAUA;IACE,wBAcC;IAZC,gBAAgC;IAChC,sBAA8C;IAC9C,oCAAuC;IACvC,iBAAuB;IACvB,gDAA4B;IAC5B,2BAAiC;IACjC,sCAA4B;IAsD9B,2CAGC;IAjDD,4BA4CC;IAhDC,0BAAgD;IAChD,iCAA8D;IAsDhE,yCAQC;IAED,sBAoBC;CACF"}
@@ -2,62 +2,16 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
2
2
  /* eslint-disable react-refresh/only-export-components */
3
3
  import React, { PureComponent, Suspense } from 'react';
4
4
  import { ChunkWorker } from '@vitessce/neuroglancer-workers';
5
- import { isEqualWith, pick } from 'lodash-es';
6
5
  import { NeuroglancerGlobalStyles } from './styles.js';
7
6
  const LazyReactNeuroglancer = React.lazy(() => import('./ReactNeuroglancer.js'));
8
7
  function createWorker() {
9
8
  return new ChunkWorker();
10
9
  }
11
- /**
12
- * Is this a valid viewerState object?
13
- * @param {object} viewerState
14
- * @returns {boolean}
15
- */
16
- function isValidState(viewerState) {
17
- const { projectionScale, projectionOrientation, position, dimensions } = viewerState || {};
18
- return (dimensions !== undefined
19
- && typeof projectionScale === 'number'
20
- && Array.isArray(projectionOrientation)
21
- && projectionOrientation.length === 4
22
- && Array.isArray(position)
23
- && position.length === 3);
24
- }
25
- // TODO: Do we want to use the same epsilon value
26
- // for every viewstate property being compared?
27
- const EPSILON = 1e-7;
28
- const VIEWSTATE_KEYS = ['projectionScale', 'projectionOrientation', 'position'];
29
- // Custom numeric comparison function
30
- // for isEqualWith, to be able to set a custom epsilon.
31
- function customizer(a, b) {
32
- if (typeof a === 'number' && typeof b === 'number') {
33
- // Returns true if the values are equivalent, else false.
34
- return Math.abs(a - b) > EPSILON;
35
- }
36
- // Return undefined to fallback to the default
37
- // comparison function.
38
- return undefined;
39
- }
40
- /**
41
- * Returns true if the two states are equal, or false if not.
42
- * @param {object} prevState Previous viewer state.
43
- * @param {object} nextState Next viewer state.
44
- * @returns
45
- */
46
- function compareViewerState(prevState, nextState) {
47
- if (isValidState(nextState)) {
48
- // Subset the viewerState objects to only the keys
49
- // that we want to use for comparison.
50
- const prevSubset = pick(prevState, VIEWSTATE_KEYS);
51
- const nextSubset = pick(nextState, VIEWSTATE_KEYS);
52
- return isEqualWith(prevSubset, nextSubset, customizer);
53
- }
54
- return true;
55
- }
56
- export class Neuroglancer extends PureComponent {
10
+ export class NeuroglancerComp extends PureComponent {
57
11
  constructor(props) {
58
12
  super(props);
59
13
  this.bundleRoot = createWorker();
60
- this.viewerState = props.viewerState;
14
+ this.cellColorMapping = props.cellColorMapping;
61
15
  this.justReceivedExternalUpdate = false;
62
16
  this.prevElement = null;
63
17
  this.prevClickHandler = null;
@@ -65,65 +19,70 @@ export class Neuroglancer extends PureComponent {
65
19
  this.prevHoverHandler = null;
66
20
  this.onViewerStateChanged = this.onViewerStateChanged.bind(this);
67
21
  this.onRef = this.onRef.bind(this);
22
+ // To avoid closure for onSegmentClick(), to update the selection
23
+ this.latestOnSegmentClick = props.onSegmentClick;
24
+ this.latestOnSelectHoveredCoords = props.onSelectHoveredCoords;
68
25
  }
69
26
  onRef(viewerRef) {
70
27
  // Here, we have access to the viewerRef.viewer object,
71
28
  // which we can use to add/remove event handlers.
72
- const { onSegmentClick, onSelectHoveredCoords, } = this.props;
73
29
  if (viewerRef) {
74
30
  // Mount
75
31
  const { viewer } = viewerRef;
76
32
  this.prevElement = viewer.element;
77
33
  this.prevMouseStateChanged = viewer.mouseState.changed;
34
+ viewer.inputEventBindings.sliceView.set('at:dblclick0', () => { });
35
+ viewer.inputEventBindings.perspectiveView.set('at:dblclick0', () => { });
78
36
  this.prevClickHandler = (event) => {
79
37
  if (event.button === 0) {
80
- setTimeout(() => {
81
- const { pickedValue } = viewer.mouseState;
82
- if (pickedValue && pickedValue?.low) {
83
- onSegmentClick(pickedValue?.low);
38
+ // Wait for mouseState to update
39
+ requestAnimationFrame(() => {
40
+ const { pickedValue, pickedRenderLayer } = viewer.mouseState;
41
+ // Only trigger selection when a segment is clicked rather than any click on the view
42
+ if (pickedValue && pickedValue.low !== undefined && pickedRenderLayer) {
43
+ this.latestOnSegmentClick?.(pickedValue.low);
84
44
  }
85
- }, 100);
45
+ });
86
46
  }
87
47
  };
88
- viewer.element.addEventListener('mousedown', this.prevClickHandler);
89
48
  this.prevHoverHandler = () => {
90
49
  if (viewer.mouseState.pickedValue !== undefined) {
91
50
  const pickedSegment = viewer.mouseState.pickedValue;
92
- onSelectHoveredCoords(pickedSegment?.low);
51
+ this.latestOnSelectHoveredCoords?.(pickedSegment?.low);
93
52
  }
94
53
  };
54
+ viewer.element.addEventListener('mouseup', this.prevClickHandler);
95
55
  viewer.mouseState.changed.add(this.prevHoverHandler);
96
56
  }
97
57
  else {
98
58
  // Unmount (viewerRef is null)
99
59
  if (this.prevElement && this.prevClickHandler) {
100
- this.prevElement.removeEventListener('mousedown', this.prevClickHandler);
60
+ this.prevElement.removeEventListener('mouseup', this.prevClickHandler);
61
+ this.prevClickHandler = null;
101
62
  }
102
63
  if (this.prevMouseStateChanged && this.prevHoverHandler) {
103
64
  this.prevMouseStateChanged.remove(this.prevHoverHandler);
65
+ this.prevHoverHandler = null;
104
66
  }
67
+ this.prevElement = null;
68
+ this.prevMouseStateChanged = null;
105
69
  }
106
70
  }
107
71
  onViewerStateChanged(nextState) {
108
72
  const { setViewerState } = this.props;
109
- const { viewerState: prevState } = this;
110
- if (!this.justReceivedExternalUpdate && !compareViewerState(prevState, nextState)) {
111
- this.viewerState = nextState;
112
- this.justReceivedExternalUpdate = false;
113
- setViewerState(nextState);
114
- }
73
+ setViewerState(nextState);
115
74
  }
116
- UNSAFE_componentWillUpdate(prevProps) {
117
- if (!compareViewerState(this.viewerState, prevProps.viewerState)) {
118
- this.viewerState = prevProps.viewerState;
119
- this.justReceivedExternalUpdate = true;
120
- setTimeout(() => {
121
- this.justReceivedExternalUpdate = false;
122
- }, 100);
75
+ componentDidUpdate(prevProps) {
76
+ const { onSegmentClick, onSelectHoveredCoords } = this.props;
77
+ if (prevProps.onSegmentClick !== onSegmentClick) {
78
+ this.latestOnSegmentClick = onSegmentClick;
79
+ }
80
+ if (prevProps.onSelectHoveredCoords !== onSelectHoveredCoords) {
81
+ this.latestOnSelectHoveredCoords = onSelectHoveredCoords;
123
82
  }
124
83
  }
125
84
  render() {
126
- const { classes, } = this.props;
127
- return (_jsxs(_Fragment, { children: [_jsx(NeuroglancerGlobalStyles, { classes: classes }), _jsx("div", { className: classes.neuroglancerWrapper, children: _jsx(Suspense, { fallback: _jsx("div", { children: "Loading..." }), children: _jsx(LazyReactNeuroglancer, { brainMapsClientId: "NOT_A_VALID_ID", viewerState: this.viewerState, onViewerStateChanged: this.onViewerStateChanged, bundleRoot: this.bundleRoot, ref: this.onRef }) }) })] }));
85
+ const { classes, viewerState, cellColorMapping } = this.props;
86
+ return (_jsxs(_Fragment, { children: [_jsx(NeuroglancerGlobalStyles, { classes: classes }), _jsx("div", { className: classes.neuroglancerWrapper, children: _jsx(Suspense, { fallback: _jsx("div", { children: "Loading..." }), children: _jsx(LazyReactNeuroglancer, { brainMapsClientId: "NOT_A_VALID_ID", viewerState: viewerState, onViewerStateChanged: this.onViewerStateChanged, bundleRoot: this.bundleRoot, cellColorMapping: cellColorMapping, ref: this.onRef }) }) })] }));
128
87
  }
129
88
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NeuroglancerSubscriber.d.ts","sourceRoot":"","sources":["../src/NeuroglancerSubscriber.js"],"names":[],"mappings":"AAiEA,gEAuKC"}
1
+ {"version":3,"file":"NeuroglancerSubscriber.d.ts","sourceRoot":"","sources":["../src/NeuroglancerSubscriber.js"],"names":[],"mappings":"AAiDA,gEA2dC"}