@vitessce/vit-s 2.0.0-beta.0

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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/dist/CallbackPublisher.js +68 -0
  3. package/dist/LoadingIndicator.js +27 -0
  4. package/dist/TitleInfo.js +151 -0
  5. package/dist/VitS.js +113 -0
  6. package/dist/Vitessce.integration.test.js +36 -0
  7. package/dist/Vitessce.js +101 -0
  8. package/dist/VitessceGrid.js +55 -0
  9. package/dist/VitessceGrid.test.js +36 -0
  10. package/dist/Warning.js +45 -0
  11. package/dist/classNames.js +8 -0
  12. package/dist/component-registry.js +16 -0
  13. package/dist/data/AbstractLoader.js +35 -0
  14. package/dist/data/AbstractTwoStepLoader.js +7 -0
  15. package/dist/data/LoaderResult.js +7 -0
  16. package/dist/data/index.js +3 -0
  17. package/dist/data/loader-registry.js +15 -0
  18. package/dist/data-hook-utils.js +175 -0
  19. package/dist/data-hooks.js +241 -0
  20. package/dist/errors/AbstractLoaderError.js +13 -0
  21. package/dist/errors/DataSourceFetchError.js +13 -0
  22. package/dist/errors/DatasetNotFoundError.js +17 -0
  23. package/dist/errors/LoaderNotFoundError.js +17 -0
  24. package/dist/errors/LoaderValidationError.js +15 -0
  25. package/dist/errors/OptionsValidationError.js +15 -0
  26. package/dist/errors/index.js +6 -0
  27. package/dist/export-utils.js +70 -0
  28. package/dist/export-utils.test.js +66 -0
  29. package/dist/file-options-schemas-legacy.js +136 -0
  30. package/dist/file-options-schemas-legacy.test.js +126 -0
  31. package/dist/file-options-schemas.js +322 -0
  32. package/dist/file-options-schemas.test.js +23 -0
  33. package/dist/hooks.js +215 -0
  34. package/dist/index.js +18 -0
  35. package/dist/joint-file-types-legacy.js +278 -0
  36. package/dist/joint-file-types-legacy.test.js +400 -0
  37. package/dist/joint-file-types.js +148 -0
  38. package/dist/joint-file-types.test.js +139 -0
  39. package/dist/loader-registry.js +98 -0
  40. package/dist/plugins.js +154 -0
  41. package/dist/plugins.test.fixtures.js +76 -0
  42. package/dist/plugins.test.js +30 -0
  43. package/dist/schemas/PrettyJsonSchema.js +34 -0
  44. package/dist/schemas/config-0.1.0.schema.json +84 -0
  45. package/dist/schemas/config-1.0.0.schema.json +733 -0
  46. package/dist/schemas/config-1.0.1.schema.json +909 -0
  47. package/dist/schemas/config-1.0.10.schema.json +969 -0
  48. package/dist/schemas/config-1.0.11.schema.json +990 -0
  49. package/dist/schemas/config-1.0.12.schema.json +997 -0
  50. package/dist/schemas/config-1.0.13.schema.json +1013 -0
  51. package/dist/schemas/config-1.0.14.schema.json +1048 -0
  52. package/dist/schemas/config-1.0.15.schema.json +1048 -0
  53. package/dist/schemas/config-1.0.15.schema.test.js +22 -0
  54. package/dist/schemas/config-1.0.2.schema.json +910 -0
  55. package/dist/schemas/config-1.0.3.schema.json +910 -0
  56. package/dist/schemas/config-1.0.4.schema.json +949 -0
  57. package/dist/schemas/config-1.0.5.schema.json +949 -0
  58. package/dist/schemas/config-1.0.6.schema.json +949 -0
  59. package/dist/schemas/config-1.0.7.schema.json +949 -0
  60. package/dist/schemas/config-1.0.8.schema.json +965 -0
  61. package/dist/schemas/config-1.0.9.schema.json +965 -0
  62. package/dist/schemas/obsSets.schema.js +195 -0
  63. package/dist/schemas/obsSets.schema.json +194 -0
  64. package/dist/schemas/obsSetsTabular.schema.js +38 -0
  65. package/dist/schemas/obsSetsTabular.schema.json +37 -0
  66. package/dist/schemas/raster.schema.js +120 -0
  67. package/dist/schemas/raster.schema.json +119 -0
  68. package/dist/schemas/schema.test-old.js +50 -0
  69. package/dist/schemas/schema.test.js +46 -0
  70. package/dist/schemas.js +4 -0
  71. package/dist/shared-mui/components.js +35 -0
  72. package/dist/shared-mui/container.js +211 -0
  73. package/dist/shared-mui/styles.js +63 -0
  74. package/dist/shared-plot-options/CellColorEncodingOption.js +18 -0
  75. package/dist/shared-plot-options/OptionSelect.js +12 -0
  76. package/dist/shared-plot-options/OptionsContainer.js +12 -0
  77. package/dist/shared-plot-options/index.js +4 -0
  78. package/dist/shared-plot-options/styles.js +48 -0
  79. package/dist/state/hooks.js +550 -0
  80. package/dist/view-config-upgraders.js +525 -0
  81. package/dist/view-config-utils.js +286 -0
  82. package/dist/view-config-utils.test.fixtures.js +765 -0
  83. package/dist/view-config-utils.test.js +66 -0
  84. package/dist/view-config-versions.js +47 -0
  85. package/dist/vitessce-grid-layout/VitessceGridLayout.js +96 -0
  86. package/dist/vitessce-grid-layout/VitessceGridLayout.test.js +40 -0
  87. package/dist/vitessce-grid-layout/index.js +1 -0
  88. package/dist/vitessce-grid-layout/layout-utils.js +61 -0
  89. package/dist/vitessce-grid-layout/layout-utils.test.js +146 -0
  90. package/dist/vitessce-grid-utils.js +140 -0
  91. package/package.json +43 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,68 @@
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
+ }
@@ -0,0 +1,27 @@
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
+ }
@@ -0,0 +1,151 @@
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 ADDED
@@ -0,0 +1,113 @@
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 { muiTheme } from './shared-mui/styles';
7
+ import { ViewConfigProvider, createViewConfigStore, AuxiliaryProvider, createAuxiliaryStore, } from './state/hooks';
8
+ import VitessceGrid from './VitessceGrid';
9
+ import { Warning } from './Warning';
10
+ import CallbackPublisher from './CallbackPublisher';
11
+ import { getComponent } from './component-registry';
12
+ import { checkTypes, initialize, upgradeAndValidate, } from './view-config-utils';
13
+ // TODO(monorepo): figure out how to get the current package version from package.json
14
+ // import packageJson from '../package.json';
15
+ const packageJson = { version: 'unk' };
16
+ const generateClassName = createGenerateClassName({
17
+ disableGlobal: true,
18
+ });
19
+ function logConfig(config, name) {
20
+ console.groupCollapsed(`🚄 Vitessce (${packageJson.version}) ${name}`);
21
+ console.info(`data:,${JSON.stringify(config)}`);
22
+ console.info(JSON.stringify(config, null, 2));
23
+ console.groupEnd();
24
+ }
25
+ /**
26
+ * The Vitessce component.
27
+ * @param {object} props
28
+ * @param {object} props.config A Vitessce view config.
29
+ * If the config is valid, the VitessceGrid will be rendered as a child.
30
+ * If the config is invalid, a Warning will be rendered instead.
31
+ * @param {number} props.rowHeight Row height for grid layout. Optional.
32
+ * @param {number} props.height Total height for grid layout. Optional.
33
+ * @param {string} props.theme The theme, used for styling as
34
+ * light or dark. Optional. By default, "dark"
35
+ * @param {function} props.onWarn A callback for warning messages. Optional.
36
+ * @param {function} props.onConfigChange A callback for view config
37
+ * updates. Optional.
38
+ * @param {function} props.onLoaderChange A callback for loader
39
+ * updates. Optional.
40
+ * @param {boolean} props.validateOnConfigChange Whether to validate
41
+ * against the view config schema when publishing changes. Use for debugging
42
+ * purposes, as this may have a performance impact. By default, false.
43
+ */
44
+ export function VitS(props) {
45
+ const { config, rowHeight, height, theme, onWarn, onConfigChange, onLoaderChange, validateOnConfigChange = false, onConfigUpgrade, isBounded = false, } = props;
46
+ // Process the view config and memoize the result:
47
+ // - Validate.
48
+ // - Upgrade, if legacy schema.
49
+ // - Validate after upgrade, if legacy schema.
50
+ // - Initialize (based on initStrategy).
51
+ const [configOrWarning, success] = useMemo(() => {
52
+ // If the config value is undefined, show a warning message.
53
+ if (!config) {
54
+ return [
55
+ {
56
+ title: 'No such dataset',
57
+ unformatted: 'The dataset configuration could not be found.',
58
+ },
59
+ false,
60
+ ];
61
+ }
62
+ // If the view config is missing a version, show a warning message.
63
+ if (!config.version) {
64
+ return [
65
+ {
66
+ title: 'Missing version',
67
+ unformatted: 'The dataset configuration is missing a version, preventing validation.',
68
+ },
69
+ false,
70
+ ];
71
+ }
72
+ logConfig(config, 'input view config');
73
+ // Check if this is a "legacy" view config.
74
+ const [upgradedConfig, upgradeSuccess] = upgradeAndValidate(config, onConfigUpgrade);
75
+ if (upgradeSuccess) {
76
+ logConfig(upgradedConfig, 'upgraded view config');
77
+ // Initialize the view config according to the initStrategy.
78
+ const [typeCheckSuccess, typeCheckMessage] = checkTypes(upgradedConfig);
79
+ if (typeCheckSuccess) {
80
+ try {
81
+ const initializedConfig = initialize(upgradedConfig);
82
+ logConfig(initializedConfig, 'initialized view config');
83
+ return [initializedConfig, true];
84
+ }
85
+ catch (e) {
86
+ return [
87
+ {
88
+ title: 'View config initialization failed.',
89
+ unformatted: e.message,
90
+ },
91
+ false,
92
+ ];
93
+ }
94
+ }
95
+ return [
96
+ {
97
+ title: 'View config checks failed.',
98
+ unformatted: typeCheckMessage,
99
+ },
100
+ false,
101
+ ];
102
+ }
103
+ return [upgradedConfig, false];
104
+ }, [config, onConfigUpgrade]);
105
+ // Emit the upgraded/initialized view config
106
+ // to onConfigChange if necessary.
107
+ useEffect(() => {
108
+ if (success && !isEqual(configOrWarning, config) && onConfigChange) {
109
+ onConfigChange(configOrWarning);
110
+ }
111
+ }, [success, config, configOrWarning, onConfigChange]);
112
+ 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 }) }) }));
113
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /* eslint-disable max-len */
3
+ // import React from 'react';
4
+ // import Adapter from 'enzyme-adapter-react-16';
5
+ // import { mount, configure } from 'enzyme';
6
+ // import Ajv from 'ajv';
7
+ // import expect from 'expect';
8
+ // import Vitessce from './Vitessce';
9
+ // import { configs } from './api';
10
+ // import configSchema from '../schemas/config.schema.json';
11
+ // configure({ adapter: new Adapter() });
12
+ // describe('Vitessce.js', () => {
13
+ // describe('<Vitessce />', () => {
14
+ // it('Produces valid view config', (done) => {
15
+ // const config = configs['linnarsson-2018'];
16
+ // let updatedConfig = {};
17
+ // // eslint-disable-next-line no-return-assign
18
+ // const wrapper = mount(<Vitessce config={config} onConfigChange={c => updatedConfig = c} />);
19
+ // setTimeout(() => {
20
+ // // Simulate usage of some of the app
21
+ // wrapper.find('[id^="deckgl-overlay-"]').at(0).simulate('wheel', { deltaY: 1000, deltaX: 1000 });
22
+ // wrapper.find('[id^="deckgl-overlay-"]').at(1).simulate('wheel', { deltaY: 1000, deltaX: 1000 });
23
+ // wrapper.find('[id^="deckgl-overlay-"]').at(2).simulate('wheel', { deltaY: 1000, deltaX: 1000 });
24
+ // const validate = new Ajv().compile(configSchema);
25
+ // const valid = validate(updatedConfig);
26
+ // if (!valid) {
27
+ // const failureReason = JSON.stringify(validate.errors, null, 2);
28
+ // console.error(failureReason);
29
+ // }
30
+ // expect(valid).toEqual(true);
31
+ // wrapper.unmount();
32
+ // done();
33
+ // }, 20000);
34
+ // }).timeout(30000);
35
+ // });
36
+ // });
@@ -0,0 +1,101 @@
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 { muiTheme } from './shared-mui/styles';
7
+ import { ViewConfigProvider, createViewConfigStore, AuxiliaryProvider, createAuxiliaryStore, } from './state/hooks';
8
+ import VitessceGrid from './VitessceGrid';
9
+ import { Warning } from './Warning';
10
+ import CallbackPublisher from './CallbackPublisher';
11
+ import { getComponent } from './component-registry';
12
+ import { checkTypes, initialize, upgradeAndValidate } from './view-config-utils';
13
+ // TODO(monorepo): figure out how to get the current package version from package.json
14
+ // import packageJson from '../package.json';
15
+ const packageJson = { version: 'unk' };
16
+ const generateClassName = createGenerateClassName({
17
+ disableGlobal: true,
18
+ });
19
+ function logConfig(config, name) {
20
+ console.groupCollapsed(`🚄 Vitessce (${packageJson.version}) ${name}`);
21
+ console.info(`data:,${JSON.stringify(config)}`);
22
+ console.info(JSON.stringify(config, null, 2));
23
+ console.groupEnd();
24
+ }
25
+ /**
26
+ * The Vitessce component.
27
+ * @param {object} props
28
+ * @param {object} props.config A Vitessce view config.
29
+ * If the config is valid, the VitessceGrid will be rendered as a child.
30
+ * If the config is invalid, a Warning will be rendered instead.
31
+ * @param {number} props.rowHeight Row height for grid layout. Optional.
32
+ * @param {number} props.height Total height for grid layout. Optional.
33
+ * @param {string} props.theme The theme, used for styling as
34
+ * light or dark. Optional. By default, "dark"
35
+ * @param {function} props.onWarn A callback for warning messages. Optional.
36
+ * @param {function} props.onConfigChange A callback for view config
37
+ * updates. Optional.
38
+ * @param {function} props.onLoaderChange A callback for loader
39
+ * updates. Optional.
40
+ * @param {boolean} props.validateOnConfigChange Whether to validate
41
+ * against the view config schema when publishing changes. Use for debugging
42
+ * purposes, as this may have a performance impact. By default, false.
43
+ */
44
+ export function Vitessce(props) {
45
+ const { config, rowHeight, height, theme, onWarn, onConfigChange, onLoaderChange, validateOnConfigChange = false, onConfigUpgrade, isBounded = false, } = props;
46
+ // Process the view config and memoize the result:
47
+ // - Validate.
48
+ // - Upgrade, if legacy schema.
49
+ // - Validate after upgrade, if legacy schema.
50
+ // - Initialize (based on initStrategy).
51
+ const [configOrWarning, success] = useMemo(() => {
52
+ // If the config value is undefined, show a warning message.
53
+ if (!config) {
54
+ return [{
55
+ title: 'No such dataset',
56
+ unformatted: 'The dataset configuration could not be found.',
57
+ }, false];
58
+ }
59
+ // If the view config is missing a version, show a warning message.
60
+ if (!config.version) {
61
+ return [{
62
+ title: 'Missing version',
63
+ unformatted: 'The dataset configuration is missing a version, preventing validation.',
64
+ }, false];
65
+ }
66
+ logConfig(config, 'input view config');
67
+ // Check if this is a "legacy" view config.
68
+ const [upgradedConfig, upgradeSuccess] = upgradeAndValidate(config, onConfigUpgrade);
69
+ if (upgradeSuccess) {
70
+ logConfig(upgradedConfig, 'upgraded view config');
71
+ // Initialize the view config according to the initStrategy.
72
+ const [typeCheckSuccess, typeCheckMessage] = checkTypes(upgradedConfig);
73
+ if (typeCheckSuccess) {
74
+ try {
75
+ const initializedConfig = initialize(upgradedConfig);
76
+ logConfig(initializedConfig, 'initialized view config');
77
+ return [initializedConfig, true];
78
+ }
79
+ catch (e) {
80
+ return [{
81
+ title: 'View config initialization failed.',
82
+ unformatted: e.message,
83
+ }, false];
84
+ }
85
+ }
86
+ return [{
87
+ title: 'View config checks failed.',
88
+ unformatted: typeCheckMessage,
89
+ }, false];
90
+ }
91
+ return [upgradedConfig, false];
92
+ }, [config, onConfigUpgrade]);
93
+ // Emit the upgraded/initialized view config
94
+ // to onConfigChange if necessary.
95
+ useEffect(() => {
96
+ if (success && !isEqual(configOrWarning, config) && onConfigChange) {
97
+ onConfigChange(configOrWarning);
98
+ }
99
+ }, [success, config, configOrWarning, onConfigChange]);
100
+ 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 }) }) }));
101
+ }
@@ -0,0 +1,55 @@
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(() => (componentWidth > 0 ? changeLayout : () => { }), [changeLayout, componentWidth]);
42
+ // Update the view config and loaders in the global state.
43
+ useEffect(() => {
44
+ if (config) {
45
+ setViewConfig(config);
46
+ const loaders = createLoaders(config.datasets, config.description);
47
+ setLoaders(loaders);
48
+ }
49
+ else {
50
+ // No config found, so clear the loaders.
51
+ setLoaders({});
52
+ }
53
+ }, [config, setViewConfig, setLoaders]);
54
+ 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 })) }));
55
+ }
@@ -0,0 +1,36 @@
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
+ });
@@ -0,0 +1,45 @@
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
+ }