@vitessce/vit-s 2.0.2 → 2.0.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.
Files changed (172) hide show
  1. package/dist/index.mjs +84801 -0
  2. package/{dist → dist-tsc}/index.js +2 -2
  3. package/package.json +7 -7
  4. package/src/CallbackPublisher.js +81 -0
  5. package/src/LoadingIndicator.js +34 -0
  6. package/src/TitleInfo.js +240 -0
  7. package/src/VitS.js +180 -0
  8. package/src/VitessceGrid.js +110 -0
  9. package/src/VitessceGrid.test.jsx +48 -0
  10. package/src/Warning.js +62 -0
  11. package/{dist → src}/classNames.js +0 -0
  12. package/src/component-registry.js +21 -0
  13. package/src/data/AbstractLoader.js +46 -0
  14. package/{dist → src}/data/AbstractTwoStepLoader.js +5 -4
  15. package/src/data/LoaderResult.js +8 -0
  16. package/{dist → src}/data/index.js +0 -0
  17. package/src/data/loader-registry.js +19 -0
  18. package/src/data-hook-utils.js +197 -0
  19. package/src/data-hooks.js +354 -0
  20. package/src/errors/AbstractLoaderError.js +14 -0
  21. package/src/errors/DataSourceFetchError.js +15 -0
  22. package/src/errors/DatasetNotFoundError.js +23 -0
  23. package/src/errors/LoaderNotFoundError.js +24 -0
  24. package/src/errors/LoaderValidationError.js +23 -0
  25. package/src/errors/OptionsValidationError.js +25 -0
  26. package/{dist → src}/errors/index.js +0 -0
  27. package/src/file-options-schemas-legacy.js +139 -0
  28. package/src/file-options-schemas-legacy.test.js +138 -0
  29. package/src/file-options-schemas.js +327 -0
  30. package/src/file-options-schemas.test.js +26 -0
  31. package/src/hooks.js +252 -0
  32. package/src/index.js +101 -0
  33. package/src/joint-file-types-legacy.js +298 -0
  34. package/src/joint-file-types-legacy.test.js +412 -0
  35. package/src/joint-file-types.js +171 -0
  36. package/src/joint-file-types.test.js +144 -0
  37. package/{dist/schemas.js → src/json-schemas.js} +6 -1
  38. package/{dist → src}/plugins.js +102 -70
  39. package/src/plugins.test.fixtures.js +78 -0
  40. package/src/plugins.test.js +42 -0
  41. package/src/schemas/config-0.1.0.schema.json +85 -0
  42. package/src/schemas/config-1.0.0.schema.json +733 -0
  43. package/src/schemas/config-1.0.1.schema.json +909 -0
  44. package/src/schemas/config-1.0.10.schema.json +969 -0
  45. package/src/schemas/config-1.0.11.schema.json +990 -0
  46. package/src/schemas/config-1.0.12.schema.json +997 -0
  47. package/src/schemas/config-1.0.13.schema.json +1013 -0
  48. package/src/schemas/config-1.0.14.schema.json +1048 -0
  49. package/src/schemas/config-1.0.15.schema.json +1048 -0
  50. package/src/schemas/config-1.0.16.schema.json +1069 -0
  51. package/src/schemas/config-1.0.16.schema.test.js +32 -0
  52. package/src/schemas/config-1.0.2.schema.json +911 -0
  53. package/src/schemas/config-1.0.3.schema.json +911 -0
  54. package/src/schemas/config-1.0.4.schema.json +949 -0
  55. package/src/schemas/config-1.0.5.schema.json +949 -0
  56. package/src/schemas/config-1.0.6.schema.json +950 -0
  57. package/src/schemas/config-1.0.7.schema.json +950 -0
  58. package/src/schemas/config-1.0.8.schema.json +966 -0
  59. package/src/schemas/config-1.0.9.schema.json +965 -0
  60. package/src/schemas/fixtures/cellSets.good.json +16 -0
  61. package/src/schemas/fixtures/config-1.0.1.bad.json +1 -0
  62. package/src/schemas/fixtures/config-1.0.1.bad.message.json +11 -0
  63. package/src/schemas/fixtures/config-1.0.1.good.json +37 -0
  64. package/src/schemas/fixtures/config-1.0.2.bad.json +1 -0
  65. package/src/schemas/fixtures/config-1.0.2.bad.message.json +11 -0
  66. package/src/schemas/fixtures/config-1.0.2.good.json +38 -0
  67. package/src/schemas/fixtures/config-1.0.3.bad.json +1 -0
  68. package/src/schemas/fixtures/config-1.0.3.bad.message.json +11 -0
  69. package/src/schemas/fixtures/config-1.0.3.good.json +38 -0
  70. package/src/schemas/fixtures/obsSets.bad.json +1 -0
  71. package/src/schemas/fixtures/obsSets.bad.message.json +11 -0
  72. package/src/schemas/fixtures/obsSets.good.json +16 -0
  73. package/src/schemas/fixtures/obsSetsTabular.bad.json +1 -0
  74. package/src/schemas/fixtures/obsSetsTabular.bad.message.json +11 -0
  75. package/src/schemas/fixtures/obsSetsTabular.good.json +26 -0
  76. package/src/schemas/fixtures/raster.bad.json +1 -0
  77. package/src/schemas/fixtures/raster.bad.message.json +11 -0
  78. package/src/schemas/fixtures/raster.good.json +39 -0
  79. package/src/schemas/obsSets.schema.js +195 -0
  80. package/src/schemas/obsSetsTabular.schema.js +39 -0
  81. package/src/schemas/raster.schema.js +121 -0
  82. package/src/schemas/schema-schema.sh +34 -0
  83. package/{dist → src}/schemas/schema.test-old.js +0 -1
  84. package/src/shared-mui/components.js +79 -0
  85. package/src/shared-mui/container.js +212 -0
  86. package/src/shared-mui/styles.js +110 -0
  87. package/src/shared-plot-options/CellColorEncodingOption.js +43 -0
  88. package/src/shared-plot-options/OptionSelect.js +19 -0
  89. package/src/shared-plot-options/OptionsContainer.js +26 -0
  90. package/{dist → src}/shared-plot-options/index.js +0 -0
  91. package/src/shared-plot-options/styles.js +49 -0
  92. package/src/state/hooks.js +633 -0
  93. package/src/view-config-upgraders.js +628 -0
  94. package/src/view-config-utils.js +315 -0
  95. package/src/view-config-utils.test.fixtures.js +893 -0
  96. package/src/view-config-utils.test.js +95 -0
  97. package/src/view-config-versions.js +68 -0
  98. package/src/vitessce-grid-layout/VitessceGridLayout.js +158 -0
  99. package/src/vitessce-grid-layout/VitessceGridLayout.test.jsx +56 -0
  100. package/{dist → src}/vitessce-grid-layout/index.js +0 -0
  101. package/src/vitessce-grid-layout/layout-utils.js +76 -0
  102. package/src/vitessce-grid-layout/layout-utils.test.js +167 -0
  103. package/src/vitessce-grid-utils.js +160 -0
  104. package/dist/CallbackPublisher.js +0 -68
  105. package/dist/LoadingIndicator.js +0 -27
  106. package/dist/TitleInfo.js +0 -151
  107. package/dist/VitS.js +0 -112
  108. package/dist/VitessceGrid.js +0 -59
  109. package/dist/VitessceGrid.test.js +0 -36
  110. package/dist/Warning.js +0 -45
  111. package/dist/component-registry.js +0 -16
  112. package/dist/data/AbstractLoader.js +0 -35
  113. package/dist/data/LoaderResult.js +0 -7
  114. package/dist/data/loader-registry.js +0 -15
  115. package/dist/data-hook-utils.js +0 -175
  116. package/dist/data-hooks.js +0 -241
  117. package/dist/errors/AbstractLoaderError.js +0 -13
  118. package/dist/errors/DataSourceFetchError.js +0 -13
  119. package/dist/errors/DatasetNotFoundError.js +0 -17
  120. package/dist/errors/LoaderNotFoundError.js +0 -17
  121. package/dist/errors/LoaderValidationError.js +0 -15
  122. package/dist/errors/OptionsValidationError.js +0 -15
  123. package/dist/file-options-schemas-legacy.js +0 -136
  124. package/dist/file-options-schemas-legacy.test.js +0 -126
  125. package/dist/file-options-schemas.js +0 -322
  126. package/dist/file-options-schemas.test.js +0 -23
  127. package/dist/hooks.js +0 -215
  128. package/dist/joint-file-types-legacy.js +0 -278
  129. package/dist/joint-file-types-legacy.test.js +0 -400
  130. package/dist/joint-file-types.js +0 -148
  131. package/dist/joint-file-types.test.js +0 -139
  132. package/dist/plugins.test.fixtures.js +0 -76
  133. package/dist/plugins.test.js +0 -30
  134. package/dist/schemas/config-0.1.0.schema.json +0 -84
  135. package/dist/schemas/config-1.0.0.schema.json +0 -733
  136. package/dist/schemas/config-1.0.1.schema.json +0 -909
  137. package/dist/schemas/config-1.0.10.schema.json +0 -969
  138. package/dist/schemas/config-1.0.11.schema.json +0 -990
  139. package/dist/schemas/config-1.0.12.schema.json +0 -997
  140. package/dist/schemas/config-1.0.13.schema.json +0 -1013
  141. package/dist/schemas/config-1.0.14.schema.json +0 -1048
  142. package/dist/schemas/config-1.0.15.schema.json +0 -1048
  143. package/dist/schemas/config-1.0.15.schema.test.js +0 -22
  144. package/dist/schemas/config-1.0.2.schema.json +0 -910
  145. package/dist/schemas/config-1.0.3.schema.json +0 -910
  146. package/dist/schemas/config-1.0.4.schema.json +0 -949
  147. package/dist/schemas/config-1.0.5.schema.json +0 -949
  148. package/dist/schemas/config-1.0.6.schema.json +0 -949
  149. package/dist/schemas/config-1.0.7.schema.json +0 -949
  150. package/dist/schemas/config-1.0.8.schema.json +0 -965
  151. package/dist/schemas/config-1.0.9.schema.json +0 -965
  152. package/dist/schemas/obsSets.schema.js +0 -195
  153. package/dist/schemas/obsSetsTabular.schema.js +0 -38
  154. package/dist/schemas/raster.schema.js +0 -120
  155. package/dist/shared-mui/components.js +0 -35
  156. package/dist/shared-mui/container.js +0 -211
  157. package/dist/shared-mui/styles.js +0 -73
  158. package/dist/shared-plot-options/CellColorEncodingOption.js +0 -18
  159. package/dist/shared-plot-options/OptionSelect.js +0 -12
  160. package/dist/shared-plot-options/OptionsContainer.js +0 -12
  161. package/dist/shared-plot-options/styles.js +0 -48
  162. package/dist/state/hooks.js +0 -549
  163. package/dist/view-config-upgraders.js +0 -525
  164. package/dist/view-config-utils.js +0 -286
  165. package/dist/view-config-utils.test.fixtures.js +0 -765
  166. package/dist/view-config-utils.test.js +0 -66
  167. package/dist/view-config-versions.js +0 -47
  168. package/dist/vitessce-grid-layout/VitessceGridLayout.js +0 -95
  169. package/dist/vitessce-grid-layout/VitessceGridLayout.test.js +0 -40
  170. package/dist/vitessce-grid-layout/layout-utils.js +0 -60
  171. package/dist/vitessce-grid-layout/layout-utils.test.js +0 -146
  172. package/dist/vitessce-grid-utils.js +0 -140
@@ -0,0 +1,160 @@
1
+ import {
2
+ useState, useEffect, useRef,
3
+ } from 'react';
4
+ import { InternMap } from 'internmap';
5
+ import isEqual from 'lodash/isEqual';
6
+ import pick from 'lodash/pick';
7
+ import { DEFAULT_COORDINATION_VALUES, DATA_TYPE_COORDINATION_VALUE_USAGE } from '@vitessce/constants-internal';
8
+ import { getSourceAndLoaderFromFileType } from './data/loader-registry';
9
+ import { getFileTypeDataTypeMapping } from './plugins';
10
+
11
+ /**
12
+ * Return the bottom coordinate of the layout.
13
+ * https://github.com/STRML/react-grid-layout/blob/20dac73f91274526034c00968b5bedb9c2ed36b9/lib/utils.js#L82
14
+ * @param {array} layout react-grid-layout layout array.
15
+ * @returns {number} Bottom coordinate.
16
+ */
17
+ function getNumRows(layout) {
18
+ let max = 0;
19
+ let bottomY;
20
+ // eslint-disable-next-line no-plusplus
21
+ for (let i = 0, len = layout.length; i < len; i++) {
22
+ bottomY = layout[i].y + layout[i].h;
23
+ if (bottomY > max) max = bottomY;
24
+ }
25
+ return max;
26
+ }
27
+
28
+ /**
29
+ * Compute the row height based on the container height, number of rows,
30
+ * and margin/padding. Basically the reverse of the react-grid-layout's
31
+ * `.containerHeight()` function.
32
+ * https://github.com/STRML/react-grid-layout/blob/83251e5e682abfa3252ff89d4bacf47fdc1f4270/lib/ReactGridLayout.jsx#L223
33
+ * @param {number} containerHeight The height of the .vitessce-container element.
34
+ * @param {number} numRows The number of rows in the layout.
35
+ * @param {number} margin The margin value that will be passed to VitessceGrid.
36
+ * @param {number} padding The padding value that will be passed to VitessceGrid.
37
+ * @returns {number} The new row height value.
38
+ */
39
+ function getRowHeight(containerHeight, numRows, margin, padding) {
40
+ const effectiveContainerHeight = containerHeight - 2 * padding - (numRows - 1) * margin;
41
+ return effectiveContainerHeight / numRows;
42
+ }
43
+
44
+ export function useRowHeight(config, initialRowHeight, height, margin, padding) {
45
+ const [containerHeight, setContainerHeight] = useState(height);
46
+ const [rowHeight, setRowHeight] = useState(initialRowHeight);
47
+ const containerRef = useRef();
48
+
49
+ // Detect when the `config` or `containerHeight` variables
50
+ // have changed, and update `rowHeight` in response.
51
+ useEffect(() => {
52
+ const numRows = getNumRows(config.layout);
53
+ const newRowHeight = getRowHeight(containerHeight, numRows, margin, padding);
54
+ setRowHeight(newRowHeight);
55
+ }, [containerHeight, config, margin, padding]);
56
+
57
+ // Update the `containerHeight` state when the `height` prop has changed.
58
+ useEffect(() => {
59
+ if (height !== null && height !== undefined) {
60
+ setContainerHeight(height);
61
+ }
62
+ }, [height]);
63
+
64
+ // If no height prop has been provided, set the `containerHeight`
65
+ // using height of the `.vitessce-container` element.
66
+ // Check the container element height whenever the window has been
67
+ // resized, as it may change if `.vitessce-container` should be
68
+ // sized relative to its parent (and by extension, potentially the window).
69
+ useEffect(() => {
70
+ if (height !== null && height !== undefined) {
71
+ // eslint will complain if the return value is inconsistent,
72
+ // so return a no-op function.
73
+ return () => {};
74
+ }
75
+ function onWindowResize() {
76
+ if (!containerRef.current) return;
77
+ const containerRect = containerRef.current.getBoundingClientRect();
78
+ setContainerHeight(containerRect.height);
79
+ }
80
+ window.addEventListener('resize', onWindowResize);
81
+ onWindowResize();
82
+ return () => {
83
+ window.removeEventListener('resize', onWindowResize);
84
+ };
85
+ }, [containerRef, height]);
86
+
87
+
88
+ return [rowHeight, containerRef];
89
+ }
90
+
91
+ function withDefaults(coordinationValues, dataType, fileType, datasetUid) {
92
+ const defaultKeys = DATA_TYPE_COORDINATION_VALUE_USAGE[dataType]
93
+ .filter(k => (
94
+ Object.keys(DEFAULT_COORDINATION_VALUES).includes(k)
95
+ && DEFAULT_COORDINATION_VALUES[k]
96
+ && !Object.keys(coordinationValues).includes(k)
97
+ ));
98
+ const defaultValues = pick(DEFAULT_COORDINATION_VALUES, defaultKeys);
99
+ const coordinationValuesWithDefaults = {
100
+ ...defaultValues,
101
+ // The user-provided values should take precedence.
102
+ ...coordinationValues,
103
+ };
104
+ if (!isEqual(coordinationValues, coordinationValuesWithDefaults)) {
105
+ // eslint-disable-next-line max-len
106
+ console.warn(`Using coordination value defaults for file type ${fileType} in dataset ${datasetUid}\nBefore: ${JSON.stringify(coordinationValues)}\nAfter: ${JSON.stringify(coordinationValuesWithDefaults)}`);
107
+ }
108
+ return coordinationValuesWithDefaults;
109
+ }
110
+
111
+ /**
112
+ * Create a mapping from dataset ID to loader objects by data type.
113
+ * @param {object[]} datasets The datasets array from the view config.
114
+ * @param {string} configDescription The top-level description in the
115
+ * view config.
116
+ * @returns {object} Mapping from dataset ID to data type to loader
117
+ * instance.
118
+ */
119
+ export function createLoaders(datasets, configDescription) {
120
+ const result = {};
121
+ const dataSources = {};
122
+ const fileTypeDataTypeMapping = getFileTypeDataTypeMapping();
123
+ datasets.forEach((dataset) => {
124
+ const datasetLoaders = {
125
+ name: dataset.name,
126
+ description: dataset.description || configDescription,
127
+ loaders: {},
128
+ };
129
+ dataset.files.forEach((file) => {
130
+ const {
131
+ url,
132
+ options,
133
+ requestInit,
134
+ fileType,
135
+ coordinationValues = {},
136
+ } = file;
137
+ const dataType = fileTypeDataTypeMapping[fileType];
138
+ const coordinationValuesWithDefaults = withDefaults(
139
+ coordinationValues, dataType,
140
+ fileType, dataset.uid,
141
+ );
142
+ const [DataSourceClass, LoaderClass] = getSourceAndLoaderFromFileType(fileType);
143
+ // Create _one_ DataSourceClass instance per URL. Derived loaders share this object.
144
+ const fileId = url || JSON.stringify(options);
145
+ if (!(fileId in dataSources)) {
146
+ dataSources[fileId] = new DataSourceClass({ url, requestInit });
147
+ }
148
+ const loader = new LoaderClass(dataSources[fileId], file);
149
+ if (datasetLoaders.loaders[dataType]) {
150
+ datasetLoaders.loaders[dataType].set(coordinationValuesWithDefaults, loader);
151
+ } else {
152
+ datasetLoaders.loaders[dataType] = new InternMap([
153
+ [coordinationValuesWithDefaults, loader],
154
+ ], JSON.stringify);
155
+ }
156
+ });
157
+ result[dataset.uid] = datasetLoaders;
158
+ });
159
+ return result;
160
+ }
@@ -1,68 +0,0 @@
1
- import { useEffect } from 'react';
2
- import { SCHEMA_HANDLERS, LATEST_VERSION } from './view-config-versions';
3
- import { useViewConfigStoreApi, useLoaders, useWarning } from './state/hooks';
4
- function validateViewConfig(viewConfig) {
5
- // Need the try-catch here since Zustand will actually
6
- // just catch and ignore errors in its subscription callbacks.
7
- try {
8
- const validate = SCHEMA_HANDLERS[LATEST_VERSION][0];
9
- const valid = validate(viewConfig);
10
- if (!valid) {
11
- const failureReason = JSON.stringify(validate.errors, null, 2);
12
- throw new Error(`Config validation failed: ${failureReason}`);
13
- }
14
- }
15
- catch (e) {
16
- console.error(e);
17
- }
18
- // Do nothing if successful.
19
- }
20
- /**
21
- * This is a dummy component which handles
22
- * publishing new view configs and loaders to
23
- * the provided callbacks on changes.
24
- * @param {object} props
25
- * @param {function} props.onConfigChange A callback function
26
- * to execute on each change of the Vitessce view config.
27
- * @param {function} props.onLoaderChange A callback function
28
- * to execute on each change of the loaders object.
29
- * @param {boolean} props.validateOnConfigChange Whether to validate
30
- * against the view config schema when publishing changes.
31
- */
32
- export default function CallbackPublisher(props) {
33
- const { onWarn, onConfigChange, onLoaderChange, validateOnConfigChange, } = props;
34
- const warning = useWarning();
35
- const loaders = useLoaders();
36
- const viewConfigStoreApi = useViewConfigStoreApi();
37
- // View config updates are often-occurring, so
38
- // we want to use the "transient update" approach
39
- // to subscribe to view config changes.
40
- // Reference: https://github.com/react-spring/zustand#transient-updates-for-often-occuring-state-changes
41
- useEffect(() => viewConfigStoreApi.subscribe(
42
- // The function to run on each publish.
43
- (viewConfig) => {
44
- if (validateOnConfigChange && viewConfig) {
45
- validateViewConfig(viewConfig);
46
- }
47
- if (onConfigChange && viewConfig) {
48
- onConfigChange(viewConfig);
49
- }
50
- },
51
- // The function to specify which part of the store
52
- // we want to subscribe to.
53
- state => state.viewConfig), [onConfigChange, validateOnConfigChange, viewConfigStoreApi]);
54
- // Emit updates to the warning message.
55
- useEffect(() => {
56
- if (onWarn && warning) {
57
- onWarn(warning);
58
- }
59
- }, [warning, onWarn]);
60
- // Emit updates to the loaders.
61
- useEffect(() => {
62
- if (onLoaderChange && loaders) {
63
- onLoaderChange(loaders);
64
- }
65
- }, [loaders, onLoaderChange]);
66
- // Render nothing.
67
- return null;
68
- }
@@ -1,27 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React from 'react';
3
- import { makeStyles } from '@material-ui/core/styles';
4
- import CircularProgress from '@material-ui/core/CircularProgress';
5
- const useStyles = makeStyles(() => ({
6
- loadingIndicatorBackdrop: {
7
- position: 'absolute',
8
- top: '0',
9
- left: '0',
10
- zIndex: '1040',
11
- width: '100%',
12
- height: '100%',
13
- borderRadius: '0.25rem',
14
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
15
- },
16
- loadingIndicatorContainer: {
17
- display: 'grid',
18
- placeItems: 'center',
19
- position: 'absolute',
20
- width: '100%',
21
- height: '100%',
22
- },
23
- }));
24
- export default function LoadingIndicator() {
25
- const classes = useStyles();
26
- return (_jsx("div", { className: classes.loadingIndicatorBackdrop, children: _jsx("div", { className: classes.loadingIndicatorContainer, children: _jsx(CircularProgress, {}) }) }));
27
- }
package/dist/TitleInfo.js DELETED
@@ -1,151 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React, { useState } from 'react';
3
- import clsx from 'clsx';
4
- import { makeStyles } from '@material-ui/core/styles';
5
- import CloudDownloadIcon from '@material-ui/icons/CloudDownload';
6
- import MenuItem from '@material-ui/core/MenuItem';
7
- import IconButton from '@material-ui/core/IconButton';
8
- import Link from '@material-ui/core/Link';
9
- import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
10
- import ArrowDropUpIcon from '@material-ui/icons/ArrowDropUp';
11
- import SettingsIcon from '@material-ui/icons/Settings';
12
- import CloseIcon from '@material-ui/icons/Close';
13
- import { TOOLTIP_ANCESTOR } from './classNames';
14
- import LoadingIndicator from './LoadingIndicator';
15
- import { PopperMenu } from './shared-mui/components';
16
- const useStyles = makeStyles(theme => ({
17
- iconButton: {
18
- border: 'none',
19
- marginLeft: 0,
20
- background: 'none',
21
- color: theme.palette.primaryForeground,
22
- paddingLeft: '0.25em',
23
- paddingRight: '0.25em',
24
- borderRadius: '2px',
25
- '&:hover': {
26
- backgroundColor: theme.palette.primaryBackgroundLight,
27
- },
28
- '&:first-child': {
29
- marginLeft: '0.25em',
30
- },
31
- '&:last-child': {
32
- marginRight: '0.25em',
33
- },
34
- '& svg': {
35
- width: '0.7em',
36
- height: '0.7em',
37
- verticalAlign: 'middle',
38
- overflow: 'visible',
39
- },
40
- },
41
- downloadLink: {
42
- color: theme.palette.primaryForeground,
43
- },
44
- }));
45
- function SettingsIconWithArrow({ open }) {
46
- return (_jsxs(_Fragment, { children: [_jsx(SettingsIcon, {}), open ? _jsx(ArrowDropUpIcon, {}) : _jsx(ArrowDropDownIcon, {})] }));
47
- }
48
- function PlotOptions(props) {
49
- const { options } = props;
50
- const [open, setOpen] = useState(false);
51
- const classes = useStyles();
52
- return (options ? (_jsx(PopperMenu, { open: open, setOpen: setOpen, buttonIcon: _jsx(SettingsIconWithArrow, { open: open }), buttonClassName: classes.iconButton, placement: "bottom-end", children: options })) : null);
53
- }
54
- function CloudDownloadIconWithArrow({ open }) {
55
- return (_jsxs(_Fragment, { children: [_jsx(CloudDownloadIcon, {}), open ? _jsx(ArrowDropUpIcon, {}) : _jsx(ArrowDropDownIcon, {})] }));
56
- }
57
- function DownloadOptions(props) {
58
- const { urls } = props;
59
- const [open, setOpen] = useState(false);
60
- const classes = useStyles();
61
- return (urls && urls.length ? (_jsx(PopperMenu, { open: open, setOpen: setOpen, buttonIcon: _jsx(CloudDownloadIconWithArrow, { open: open }), buttonClassName: classes.iconButton, placement: "bottom-end", children: urls.map(({ url, name }) => (_jsx(MenuItem, { dense: true, children: _jsxs(Link, { underline: "none", href: url, target: "_blank", rel: "noopener", className: classes.downloadLink, children: ["Download ", name] }) }, `${url}_${name}`))) })) : null);
62
- }
63
- function ClosePaneButton(props) {
64
- const { removeGridComponent } = props;
65
- const classes = useStyles();
66
- return (_jsx(IconButton, { onClick: removeGridComponent, size: "small", className: classes.iconButton, title: "close", children: _jsx(CloseIcon, {}) }));
67
- }
68
- export const useTitleStyles = makeStyles(theme => ({
69
- title: {
70
- color: theme.palette.primaryForeground,
71
- overflowX: 'hidden',
72
- display: 'flex',
73
- flexDirection: 'row',
74
- flexShrink: '0',
75
- },
76
- titleLeft: {
77
- flexShrink: '1',
78
- textOverflow: 'ellipsis',
79
- whiteSpace: 'nowrap',
80
- },
81
- titleInfo: {
82
- width: '100%',
83
- textOverflow: 'ellipsis',
84
- whiteSpace: 'nowrap',
85
- overflow: 'hidden',
86
- fontSize: '80% !important',
87
- opacity: '.8',
88
- padding: '0 0.25rem',
89
- justifyContent: 'center',
90
- lineHeight: '25px !important',
91
- flexShrink: '1',
92
- textAlign: 'right !important',
93
- },
94
- titleButtons: {
95
- display: 'flex',
96
- flexDirection: 'row',
97
- flexGrow: '1',
98
- flexShrink: '0',
99
- justifyContent: 'right',
100
- '& div': {
101
- display: 'inline-block',
102
- },
103
- },
104
- card: {
105
- border: `1px solid ${theme.palette.cardBorder}`,
106
- flex: '1 1 auto',
107
- minHeight: '1px',
108
- padding: '0.75rem',
109
- marginTop: '0.5rem',
110
- marginBottom: '0.5rem',
111
- position: 'relative',
112
- display: 'flex',
113
- flexDirection: 'column',
114
- minWidth: '0',
115
- wordWrap: 'break-word',
116
- backgroundClip: 'border-box',
117
- borderRadius: '0.25rem',
118
- },
119
- noScrollCard: {
120
- backgroundColor: theme.palette.secondaryBackground,
121
- color: theme.palette.secondaryForeground,
122
- },
123
- scrollCard: {
124
- backgroundColor: theme.palette.primaryBackground,
125
- color: theme.palette.primaryForeground,
126
- '& a': {
127
- color: theme.palette.primaryForegroundActive,
128
- },
129
- overflowY: 'auto',
130
- },
131
- spatialCard: {
132
- backgroundColor: theme.palette.black,
133
- color: theme.palette.white,
134
- '& a': {
135
- color: theme.palette.white,
136
- },
137
- },
138
- }));
139
- export function TitleInfo(props) {
140
- const { title, info, children, isScroll, isSpatial, removeGridComponent, urls, isReady, options, } = props;
141
- const classes = useTitleStyles();
142
- return (
143
- // d-flex without wrapping div is not always full height; I don't understand the root cause.
144
- _jsxs(_Fragment, { children: [_jsxs("div", { className: classes.title, children: [_jsx("div", { className: classes.titleLeft, children: title }), _jsx("div", { className: classes.titleInfo, title: info, children: info }), _jsxs("div", { className: classes.titleButtons, children: [_jsx(PlotOptions, { options: options }), _jsx(DownloadOptions, { urls: urls }), _jsx(ClosePaneButton, { removeGridComponent: removeGridComponent })] })] }), _jsxs("div", { className: clsx(TOOLTIP_ANCESTOR, classes.card, {
145
- [classes.scrollCard]: isScroll,
146
- [classes.spatialCard]: isSpatial,
147
- [classes.noScrollCard]: !isScroll && !isSpatial,
148
- }), children: [!isReady && _jsx(LoadingIndicator, {}), children] })] })
149
- // "pl-2" only matters when the window is very narrow.
150
- );
151
- }
package/dist/VitS.js DELETED
@@ -1,112 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- /* eslint-disable camelcase */
3
- import React, { useEffect, useMemo } from 'react';
4
- import { ThemeProvider, StylesProvider, createGenerateClassName, } from '@material-ui/core/styles';
5
- import isEqual from 'lodash/isEqual';
6
- import { META_VERSION } from '@vitessce/constants-internal';
7
- import { muiTheme } from './shared-mui/styles';
8
- import { ViewConfigProvider, createViewConfigStore, AuxiliaryProvider, createAuxiliaryStore, } from './state/hooks';
9
- import VitessceGrid from './VitessceGrid';
10
- import { Warning } from './Warning';
11
- import CallbackPublisher from './CallbackPublisher';
12
- import { getComponent } from './component-registry';
13
- import { checkTypes, initialize, upgradeAndValidate, } from './view-config-utils';
14
- const generateClassName = createGenerateClassName({
15
- disableGlobal: false,
16
- productionPrefix: 'vit', // Avoid conflicts with portal-ui MUI class names
17
- });
18
- function logConfig(config, name) {
19
- console.groupCollapsed(`🚄 Vitessce (${META_VERSION.version}) ${name}`);
20
- console.info(`data:,${JSON.stringify(config)}`);
21
- console.info(JSON.stringify(config, null, 2));
22
- console.groupEnd();
23
- }
24
- /**
25
- * The Vitessce component.
26
- * @param {object} props
27
- * @param {object} props.config A Vitessce view config.
28
- * If the config is valid, the VitessceGrid will be rendered as a child.
29
- * If the config is invalid, a Warning will be rendered instead.
30
- * @param {number} props.rowHeight Row height for grid layout. Optional.
31
- * @param {number} props.height Total height for grid layout. Optional.
32
- * @param {string} props.theme The theme, used for styling as
33
- * light or dark. Optional. By default, "dark"
34
- * @param {function} props.onWarn A callback for warning messages. Optional.
35
- * @param {function} props.onConfigChange A callback for view config
36
- * updates. Optional.
37
- * @param {function} props.onLoaderChange A callback for loader
38
- * updates. Optional.
39
- * @param {boolean} props.validateOnConfigChange Whether to validate
40
- * against the view config schema when publishing changes. Use for debugging
41
- * purposes, as this may have a performance impact. By default, false.
42
- */
43
- export function VitS(props) {
44
- const { config, rowHeight, height, theme, onWarn, onConfigChange, onLoaderChange, validateOnConfigChange = false, onConfigUpgrade, isBounded = false, } = props;
45
- // Process the view config and memoize the result:
46
- // - Validate.
47
- // - Upgrade, if legacy schema.
48
- // - Validate after upgrade, if legacy schema.
49
- // - Initialize (based on initStrategy).
50
- const [configOrWarning, success] = useMemo(() => {
51
- // If the config value is undefined, show a warning message.
52
- if (!config) {
53
- return [
54
- {
55
- title: 'No such dataset',
56
- unformatted: 'The dataset configuration could not be found.',
57
- },
58
- false,
59
- ];
60
- }
61
- // If the view config is missing a version, show a warning message.
62
- if (!config.version) {
63
- return [
64
- {
65
- title: 'Missing version',
66
- unformatted: 'The dataset configuration is missing a version, preventing validation.',
67
- },
68
- false,
69
- ];
70
- }
71
- logConfig(config, 'input view config');
72
- // Check if this is a "legacy" view config.
73
- const [upgradedConfig, upgradeSuccess] = upgradeAndValidate(config, onConfigUpgrade);
74
- if (upgradeSuccess) {
75
- logConfig(upgradedConfig, 'upgraded view config');
76
- // Initialize the view config according to the initStrategy.
77
- const [typeCheckSuccess, typeCheckMessage] = checkTypes(upgradedConfig);
78
- if (typeCheckSuccess) {
79
- try {
80
- const initializedConfig = initialize(upgradedConfig);
81
- logConfig(initializedConfig, 'initialized view config');
82
- return [initializedConfig, true];
83
- }
84
- catch (e) {
85
- return [
86
- {
87
- title: 'View config initialization failed.',
88
- unformatted: e.message,
89
- },
90
- false,
91
- ];
92
- }
93
- }
94
- return [
95
- {
96
- title: 'View config checks failed.',
97
- unformatted: typeCheckMessage,
98
- },
99
- false,
100
- ];
101
- }
102
- return [upgradedConfig, false];
103
- }, [config, onConfigUpgrade]);
104
- // Emit the upgraded/initialized view config
105
- // to onConfigChange if necessary.
106
- useEffect(() => {
107
- if (success && !isEqual(configOrWarning, config) && onConfigChange) {
108
- onConfigChange(configOrWarning);
109
- }
110
- }, [success, config, configOrWarning, onConfigChange]);
111
- return success ? (_jsx(StylesProvider, { generateClassName: generateClassName, children: _jsx(ThemeProvider, { theme: muiTheme[theme], children: _jsx(ViewConfigProvider, { createStore: createViewConfigStore, children: _jsxs(AuxiliaryProvider, { createStore: createAuxiliaryStore, children: [_jsx(VitessceGrid, { config: configOrWarning, getComponent: getComponent, rowHeight: rowHeight, height: height, theme: theme, isBounded: isBounded }), _jsx(CallbackPublisher, { onWarn: onWarn, onConfigChange: onConfigChange, onLoaderChange: onLoaderChange, validateOnConfigChange: validateOnConfigChange })] }) }) }) })) : (_jsx(StylesProvider, { generateClassName: generateClassName, children: _jsx(ThemeProvider, { theme: muiTheme[theme], children: _jsx(Warning, { ...configOrWarning }) }) }));
112
- }
@@ -1,59 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React, { useEffect, useCallback, } from 'react';
3
- import clsx from 'clsx';
4
- import { VITESSCE_CONTAINER } from './classNames';
5
- import { VitessceGridLayout } from './vitessce-grid-layout';
6
- import { useRowHeight, createLoaders } from './vitessce-grid-utils';
7
- import { useViewConfigStoreApi, useSetViewConfig, useSetLoaders, useEmitGridResize, useRemoveComponent, useChangeLayout, useLayout, } from './state/hooks';
8
- import { useClosestVitessceContainerSize, } from './hooks';
9
- import { useVitessceContainerStyles } from './shared-mui/container';
10
- import { useTitleStyles } from './TitleInfo';
11
- const padding = 10;
12
- const margin = 5;
13
- /**
14
- * The wrapper for the VitessceGrid and LoadingIndicator components.
15
- * @param {object} props
16
- * @param {number} props.rowHeight The height of each grid row. Optional.
17
- * @param {object} props.config The view config.
18
- * @param {function} props.getComponent A function that maps component names to their
19
- * React counterparts.
20
- * @param {string} props.theme The theme name.
21
- * @param {number} props.height Total height for grid. Optional.
22
- * @param {function} props.onWarn A callback for warning messages. Optional.
23
- */
24
- export default function VitessceGrid(props) {
25
- const { rowHeight: initialRowHeight, config, getComponent, theme, height, isBounded, } = props;
26
- const [rowHeight, containerRef] = useRowHeight(config, initialRowHeight, height, margin, padding);
27
- const onResize = useEmitGridResize();
28
- const [componentWidth] = useClosestVitessceContainerSize(containerRef);
29
- const classes = useVitessceContainerStyles();
30
- const titleClasses = useTitleStyles();
31
- // When the row height has changed, publish a GRID_RESIZE event.
32
- useEffect(() => {
33
- onResize();
34
- }, [rowHeight, onResize]);
35
- const viewConfigStoreApi = useViewConfigStoreApi();
36
- const setViewConfig = useSetViewConfig(viewConfigStoreApi);
37
- const setLoaders = useSetLoaders();
38
- const removeComponent = useRemoveComponent();
39
- const changeLayout = useChangeLayout();
40
- const layout = useLayout();
41
- const changeLayoutPostMount = useCallback((newComponentProps) => {
42
- if (componentWidth > 0) {
43
- changeLayout(newComponentProps);
44
- }
45
- }, [changeLayout, componentWidth]);
46
- // Update the view config and loaders in the global state.
47
- useEffect(() => {
48
- if (config) {
49
- setViewConfig(config);
50
- const loaders = createLoaders(config.datasets, config.description);
51
- setLoaders(loaders);
52
- }
53
- else {
54
- // No config found, so clear the loaders.
55
- setLoaders({});
56
- }
57
- }, [config, setViewConfig, setLoaders]);
58
- return (_jsx("div", { ref: containerRef, className: clsx(VITESSCE_CONTAINER, classes.vitessceContainer), children: layout && (_jsx(VitessceGridLayout, { layout: layout, height: height, rowHeight: rowHeight, theme: theme, getComponent: getComponent, draggableHandle: titleClasses.title, margin: margin, padding: padding, onRemoveComponent: removeComponent, onLayoutChange: changeLayoutPostMount, isBounded: isBounded, onResize: onResize, onResizeStop: onResize })) }));
59
- }
@@ -1,36 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import '@testing-library/jest-dom';
3
- import { cleanup, render, screen } from '@testing-library/react';
4
- import { afterEach } from 'vitest';
5
- import VitessceGrid from './VitessceGrid';
6
- import { ViewConfigProvider, createViewConfigStore, AuxiliaryProvider, createAuxiliaryStore, } from './state/hooks';
7
- afterEach(() => {
8
- cleanup();
9
- });
10
- describe('VitessceGrid.js', () => {
11
- describe('<VitessceGrid />', () => {
12
- it('renders', async () => {
13
- const config = {
14
- version: '1.0.0',
15
- description: 'fake description',
16
- datasets: [],
17
- name: 'fake name',
18
- layout: [
19
- {
20
- component: 'FakeComponent',
21
- props: { description: 'fake prop description' },
22
- uid: 'A',
23
- x: 0,
24
- y: 0,
25
- },
26
- ],
27
- };
28
- function FakeComponent() {
29
- return _jsx("p", { children: "FakeComponent!" });
30
- }
31
- const getComponent = () => FakeComponent;
32
- render(_jsx(ViewConfigProvider, { createStore: createViewConfigStore, children: _jsx(AuxiliaryProvider, { createStore: createAuxiliaryStore, children: _jsx(VitessceGrid, { config: config, getComponent: getComponent }) }) }));
33
- expect(await screen.findByText('FakeComponent!'));
34
- });
35
- });
36
- });
package/dist/Warning.js DELETED
@@ -1,45 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import clsx from 'clsx';
3
- import { makeStyles } from '@material-ui/core/styles';
4
- import { VITESSCE_CONTAINER } from './classNames';
5
- const useStyles = makeStyles(theme => ({
6
- warningLayout: {
7
- backgroundColor: theme.palette.gridLayoutBackground,
8
- position: 'absolute',
9
- width: '100%',
10
- height: '100vh',
11
- },
12
- containerFluid: {
13
- width: '100%',
14
- padding: '15px',
15
- marginRight: 'auto',
16
- marginLeft: 'auto',
17
- boxSizing: 'border-box',
18
- display: 'flex',
19
- },
20
- row: {
21
- flexGrow: '1',
22
- },
23
- card: {
24
- border: `1px solid ${theme.palette.cardBorder}`,
25
- flex: '1 1 auto',
26
- minHeight: '1px',
27
- padding: '0.75rem',
28
- marginTop: '0.5rem',
29
- marginBottom: '0.5rem',
30
- position: 'relative',
31
- display: 'flex',
32
- flexDirection: 'column',
33
- minWidth: '0',
34
- wordWrap: 'break-word',
35
- backgroundClip: 'border-box',
36
- borderRadius: '0.25rem',
37
- backgroundColor: theme.palette.primaryBackground,
38
- color: theme.palette.primaryForeground,
39
- },
40
- }));
41
- export function Warning(props) {
42
- const { title, preformatted, unformatted, } = props;
43
- const classes = useStyles();
44
- return (_jsx("div", { className: VITESSCE_CONTAINER, children: _jsx("div", { className: clsx(classes.warningLayout, classes.containerFluid), children: _jsx("div", { className: classes.row, children: _jsxs("div", { className: classes.card, children: [_jsx("h1", { children: title }), preformatted ? (_jsx("pre", { children: preformatted })) : null, _jsx("p", { children: unformatted })] }) }) }) }));
45
- }