@vitessce/vit-s 2.0.3-beta.0 → 3.0.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 (277) hide show
  1. package/dist/index.js +41348 -18
  2. package/dist-tsc/CallbackPublisher.d.ts +18 -0
  3. package/dist-tsc/CallbackPublisher.d.ts.map +1 -0
  4. package/{dist → dist-tsc}/CallbackPublisher.js +6 -12
  5. package/dist-tsc/LoadingIndicator.d.ts +2 -0
  6. package/dist-tsc/LoadingIndicator.d.ts.map +1 -0
  7. package/{dist → dist-tsc}/LoadingIndicator.js +1 -2
  8. package/dist-tsc/TitleInfo.d.ts +2 -0
  9. package/dist-tsc/TitleInfo.d.ts.map +1 -0
  10. package/{dist → dist-tsc}/TitleInfo.js +6 -83
  11. package/dist-tsc/VitS.d.ts +45 -0
  12. package/dist-tsc/VitS.d.ts.map +1 -0
  13. package/dist-tsc/VitS.js +119 -0
  14. package/dist-tsc/VitessceGrid.d.ts +23 -0
  15. package/dist-tsc/VitessceGrid.d.ts.map +1 -0
  16. package/{dist → dist-tsc}/VitessceGrid.js +14 -13
  17. package/dist-tsc/VitessceGrid.test.d.ts +2 -0
  18. package/dist-tsc/VitessceGrid.test.d.ts.map +1 -0
  19. package/{dist → dist-tsc}/VitessceGrid.test.js +8 -4
  20. package/dist-tsc/Warning.d.ts +2 -0
  21. package/dist-tsc/Warning.d.ts.map +1 -0
  22. package/{dist → dist-tsc}/Warning.js +2 -2
  23. package/dist-tsc/classNames.d.ts +8 -0
  24. package/dist-tsc/classNames.d.ts.map +1 -0
  25. package/dist-tsc/data/AbstractLoader.d.ts +22 -0
  26. package/dist-tsc/data/AbstractLoader.d.ts.map +1 -0
  27. package/dist-tsc/data/AbstractLoader.js +18 -0
  28. package/dist-tsc/data/AbstractTwoStepLoader.d.ts +6 -0
  29. package/dist-tsc/data/AbstractTwoStepLoader.d.ts.map +1 -0
  30. package/{dist → dist-tsc}/data/AbstractTwoStepLoader.js +1 -1
  31. package/dist-tsc/data/LoaderResult.d.ts +7 -0
  32. package/dist-tsc/data/LoaderResult.d.ts.map +1 -0
  33. package/dist-tsc/data/index.d.ts +4 -0
  34. package/dist-tsc/data/index.d.ts.map +1 -0
  35. package/dist-tsc/data/index.js +3 -0
  36. package/dist-tsc/data/loader-registry.d.ts +9 -0
  37. package/dist-tsc/data/loader-registry.d.ts.map +1 -0
  38. package/dist-tsc/data/loader-registry.js +27 -0
  39. package/dist-tsc/data-hook-utils.d.ts +69 -0
  40. package/dist-tsc/data-hook-utils.d.ts.map +1 -0
  41. package/{dist → dist-tsc}/data-hook-utils.js +4 -6
  42. package/dist-tsc/data-hooks.d.ts +77 -0
  43. package/dist-tsc/data-hooks.d.ts.map +1 -0
  44. package/{dist → dist-tsc}/data-hooks.js +4 -4
  45. package/dist-tsc/errors/AbstractLoaderError.d.ts +10 -0
  46. package/dist-tsc/errors/AbstractLoaderError.d.ts.map +1 -0
  47. package/dist-tsc/errors/DataSourceFetchError.d.ts +8 -0
  48. package/dist-tsc/errors/DataSourceFetchError.d.ts.map +1 -0
  49. package/{dist → dist-tsc}/errors/DataSourceFetchError.js +1 -1
  50. package/dist-tsc/errors/DatasetNotFoundError.d.ts +6 -0
  51. package/dist-tsc/errors/DatasetNotFoundError.d.ts.map +1 -0
  52. package/{dist → dist-tsc}/errors/DatasetNotFoundError.js +1 -1
  53. package/dist-tsc/errors/LoaderNotFoundError.d.ts +10 -0
  54. package/dist-tsc/errors/LoaderNotFoundError.d.ts.map +1 -0
  55. package/{dist → dist-tsc}/errors/LoaderNotFoundError.js +1 -1
  56. package/dist-tsc/errors/LoaderValidationError.d.ts +10 -0
  57. package/dist-tsc/errors/LoaderValidationError.d.ts.map +1 -0
  58. package/{dist → dist-tsc}/errors/LoaderValidationError.js +1 -1
  59. package/dist-tsc/errors/index.d.ts +6 -0
  60. package/dist-tsc/errors/index.d.ts.map +1 -0
  61. package/{dist → dist-tsc}/errors/index.js +5 -6
  62. package/dist-tsc/hooks.d.ts +80 -0
  63. package/dist-tsc/hooks.d.ts.map +1 -0
  64. package/{dist → dist-tsc}/hooks.js +60 -4
  65. package/dist-tsc/index.d.ts +11 -0
  66. package/dist-tsc/index.d.ts.map +1 -0
  67. package/dist-tsc/index.js +11 -0
  68. package/dist-tsc/plugins.test.fixtures.d.ts +61 -0
  69. package/dist-tsc/plugins.test.fixtures.d.ts.map +1 -0
  70. package/{dist → dist-tsc}/schemas/config-1.0.16.schema.json +21 -41
  71. package/dist-tsc/schemas/obsSets.schema.d.ts +179 -0
  72. package/dist-tsc/schemas/obsSets.schema.d.ts.map +1 -0
  73. package/dist-tsc/schemas/obsSetsTabular.schema.d.ts +57 -0
  74. package/dist-tsc/schemas/obsSetsTabular.schema.d.ts.map +1 -0
  75. package/dist-tsc/schemas/raster.schema.d.ts +239 -0
  76. package/dist-tsc/schemas/raster.schema.d.ts.map +1 -0
  77. package/dist-tsc/shared-mui/components.d.ts +2 -0
  78. package/dist-tsc/shared-mui/components.d.ts.map +1 -0
  79. package/{dist → dist-tsc}/shared-mui/components.js +2 -8
  80. package/dist-tsc/shared-mui/container.d.ts +2 -0
  81. package/dist-tsc/shared-mui/container.d.ts.map +1 -0
  82. package/{dist → dist-tsc}/shared-mui/container.js +1 -1
  83. package/dist-tsc/shared-mui/styles.d.ts +5 -0
  84. package/dist-tsc/shared-mui/styles.d.ts.map +1 -0
  85. package/{dist → dist-tsc}/shared-mui/styles.js +4 -2
  86. package/dist-tsc/shared-plot-options/CellColorEncodingOption.d.ts +2 -0
  87. package/dist-tsc/shared-plot-options/CellColorEncodingOption.d.ts.map +1 -0
  88. package/{dist → dist-tsc}/shared-plot-options/CellColorEncodingOption.js +3 -4
  89. package/dist-tsc/shared-plot-options/OptionSelect.d.ts +2 -0
  90. package/dist-tsc/shared-plot-options/OptionSelect.d.ts.map +1 -0
  91. package/{dist → dist-tsc}/shared-plot-options/OptionSelect.js +2 -2
  92. package/dist-tsc/shared-plot-options/OptionsContainer.d.ts +2 -0
  93. package/dist-tsc/shared-plot-options/OptionsContainer.d.ts.map +1 -0
  94. package/{dist → dist-tsc}/shared-plot-options/OptionsContainer.js +2 -5
  95. package/dist-tsc/shared-plot-options/index.d.ts +5 -0
  96. package/dist-tsc/shared-plot-options/index.d.ts.map +1 -0
  97. package/dist-tsc/shared-plot-options/index.js +4 -0
  98. package/dist-tsc/shared-plot-options/styles.d.ts +2 -0
  99. package/dist-tsc/shared-plot-options/styles.d.ts.map +1 -0
  100. package/{dist → dist-tsc}/shared-plot-options/styles.js +1 -1
  101. package/dist-tsc/state/hooks.d.ts +216 -0
  102. package/dist-tsc/state/hooks.d.ts.map +1 -0
  103. package/{dist → dist-tsc}/state/hooks.js +47 -21
  104. package/dist-tsc/title-styles.d.ts +2 -0
  105. package/dist-tsc/title-styles.d.ts.map +1 -0
  106. package/dist-tsc/title-styles.js +72 -0
  107. package/dist-tsc/view-config-utils.d.ts +30 -0
  108. package/dist-tsc/view-config-utils.d.ts.map +1 -0
  109. package/{dist → dist-tsc}/view-config-utils.js +32 -84
  110. package/dist-tsc/view-config-utils.test.d.ts +2 -0
  111. package/dist-tsc/view-config-utils.test.d.ts.map +1 -0
  112. package/dist-tsc/view-config-utils.test.fixtures.d.ts +1049 -0
  113. package/dist-tsc/view-config-utils.test.fixtures.d.ts.map +1 -0
  114. package/{dist → dist-tsc}/view-config-utils.test.fixtures.js +118 -0
  115. package/dist-tsc/view-config-utils.test.js +209 -0
  116. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.d.ts +8 -0
  117. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.d.ts.map +1 -0
  118. package/{dist → dist-tsc}/vitessce-grid-layout/VitessceGridLayout.js +47 -28
  119. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.test.d.ts +2 -0
  120. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.test.d.ts.map +1 -0
  121. package/{dist → dist-tsc}/vitessce-grid-layout/VitessceGridLayout.test.js +13 -5
  122. package/dist-tsc/vitessce-grid-layout/index.d.ts +2 -0
  123. package/dist-tsc/vitessce-grid-layout/index.d.ts.map +1 -0
  124. package/dist-tsc/vitessce-grid-layout/index.js +1 -0
  125. package/dist-tsc/vitessce-grid-layout/layout-utils.d.ts +15 -0
  126. package/dist-tsc/vitessce-grid-layout/layout-utils.d.ts.map +1 -0
  127. package/{dist → dist-tsc}/vitessce-grid-layout/layout-utils.js +2 -1
  128. package/dist-tsc/vitessce-grid-layout/layout-utils.test.d.ts +2 -0
  129. package/dist-tsc/vitessce-grid-layout/layout-utils.test.d.ts.map +1 -0
  130. package/{dist → dist-tsc}/vitessce-grid-layout/layout-utils.test.js +3 -1
  131. package/dist-tsc/vitessce-grid-utils.d.ts +13 -0
  132. package/dist-tsc/vitessce-grid-utils.d.ts.map +1 -0
  133. package/{dist → dist-tsc}/vitessce-grid-utils.js +15 -14
  134. package/package.json +24 -11
  135. package/src/CallbackPublisher.js +77 -0
  136. package/src/LoadingIndicator.js +33 -0
  137. package/src/TitleInfo.js +167 -0
  138. package/src/VitS.js +202 -0
  139. package/src/VitessceGrid.js +118 -0
  140. package/src/VitessceGrid.test.jsx +57 -0
  141. package/src/Warning.js +62 -0
  142. package/src/classNames.js +8 -0
  143. package/src/data/AbstractLoader.js +23 -0
  144. package/src/data/AbstractTwoStepLoader.js +8 -0
  145. package/src/data/LoaderResult.js +8 -0
  146. package/src/data/index.js +3 -0
  147. package/src/data/loader-registry.js +28 -0
  148. package/src/data-hook-utils.js +195 -0
  149. package/src/data-hooks.js +354 -0
  150. package/src/errors/AbstractLoaderError.js +14 -0
  151. package/src/errors/DataSourceFetchError.js +15 -0
  152. package/src/errors/DatasetNotFoundError.js +23 -0
  153. package/src/errors/LoaderNotFoundError.js +24 -0
  154. package/src/errors/LoaderValidationError.js +23 -0
  155. package/src/errors/index.js +5 -0
  156. package/src/hooks.js +317 -0
  157. package/src/index.js +76 -0
  158. package/src/plugins.test.fixtures.js +78 -0
  159. package/src/schemas/config-0.1.0.schema.json +85 -0
  160. package/src/schemas/config-1.0.0.schema.json +733 -0
  161. package/src/schemas/config-1.0.1.schema.json +909 -0
  162. package/src/schemas/config-1.0.10.schema.json +969 -0
  163. package/src/schemas/config-1.0.11.schema.json +990 -0
  164. package/src/schemas/config-1.0.12.schema.json +997 -0
  165. package/src/schemas/config-1.0.13.schema.json +1013 -0
  166. package/src/schemas/config-1.0.14.schema.json +1048 -0
  167. package/src/schemas/config-1.0.15.schema.json +1048 -0
  168. package/src/schemas/config-1.0.16.schema.json +1089 -0
  169. package/src/schemas/config-1.0.2.schema.json +911 -0
  170. package/src/schemas/config-1.0.3.schema.json +911 -0
  171. package/src/schemas/config-1.0.4.schema.json +949 -0
  172. package/src/schemas/config-1.0.5.schema.json +949 -0
  173. package/src/schemas/config-1.0.6.schema.json +950 -0
  174. package/src/schemas/config-1.0.7.schema.json +950 -0
  175. package/src/schemas/config-1.0.8.schema.json +966 -0
  176. package/src/schemas/config-1.0.9.schema.json +965 -0
  177. package/src/schemas/fixtures/cellSets.good.json +16 -0
  178. package/src/schemas/fixtures/config-1.0.1.bad.json +1 -0
  179. package/src/schemas/fixtures/config-1.0.1.bad.message.json +11 -0
  180. package/src/schemas/fixtures/config-1.0.1.good.json +37 -0
  181. package/src/schemas/fixtures/config-1.0.2.bad.json +1 -0
  182. package/src/schemas/fixtures/config-1.0.2.bad.message.json +11 -0
  183. package/src/schemas/fixtures/config-1.0.2.good.json +38 -0
  184. package/src/schemas/fixtures/config-1.0.3.bad.json +1 -0
  185. package/src/schemas/fixtures/config-1.0.3.bad.message.json +11 -0
  186. package/src/schemas/fixtures/config-1.0.3.good.json +38 -0
  187. package/src/schemas/fixtures/obsSets.bad.json +1 -0
  188. package/src/schemas/fixtures/obsSets.bad.message.json +11 -0
  189. package/src/schemas/fixtures/obsSets.good.json +16 -0
  190. package/src/schemas/fixtures/obsSetsTabular.bad.json +1 -0
  191. package/src/schemas/fixtures/obsSetsTabular.bad.message.json +11 -0
  192. package/src/schemas/fixtures/obsSetsTabular.good.json +26 -0
  193. package/src/schemas/fixtures/raster.bad.json +1 -0
  194. package/src/schemas/fixtures/raster.bad.message.json +11 -0
  195. package/src/schemas/fixtures/raster.good.json +39 -0
  196. package/src/schemas/obsSets.schema.js +195 -0
  197. package/src/schemas/obsSetsTabular.schema.js +39 -0
  198. package/src/schemas/raster.schema.js +121 -0
  199. package/src/schemas/schema-schema.sh +34 -0
  200. package/src/shared-mui/components.js +81 -0
  201. package/src/shared-mui/container.js +212 -0
  202. package/src/shared-mui/styles.js +113 -0
  203. package/src/shared-plot-options/CellColorEncodingOption.js +42 -0
  204. package/src/shared-plot-options/OptionSelect.js +19 -0
  205. package/src/shared-plot-options/OptionsContainer.js +23 -0
  206. package/src/shared-plot-options/index.js +4 -0
  207. package/src/shared-plot-options/styles.js +49 -0
  208. package/src/state/hooks.js +640 -0
  209. package/src/title-styles.js +73 -0
  210. package/src/view-config-utils.js +263 -0
  211. package/src/view-config-utils.test.fixtures.js +893 -0
  212. package/src/view-config-utils.test.jsx +222 -0
  213. package/src/vitessce-grid-layout/VitessceGridLayout.js +179 -0
  214. package/src/vitessce-grid-layout/VitessceGridLayout.test.jsx +64 -0
  215. package/src/vitessce-grid-layout/index.js +1 -0
  216. package/src/vitessce-grid-layout/layout-utils.js +76 -0
  217. package/src/vitessce-grid-layout/layout-utils.test.js +167 -0
  218. package/src/vitessce-grid-utils.js +172 -0
  219. package/dist/VitS.js +0 -117
  220. package/dist/Vitessce.integration.test.js +0 -36
  221. package/dist/Vitessce.js +0 -101
  222. package/dist/component-registry.js +0 -16
  223. package/dist/data/AbstractLoader.js +0 -35
  224. package/dist/data/index.js +0 -3
  225. package/dist/data/loader-registry.js +0 -15
  226. package/dist/errors/OptionsValidationError.js +0 -15
  227. package/dist/export-utils.js +0 -70
  228. package/dist/export-utils.test.js +0 -66
  229. package/dist/file-options-schemas-legacy.js +0 -136
  230. package/dist/file-options-schemas-legacy.test.js +0 -126
  231. package/dist/file-options-schemas.js +0 -322
  232. package/dist/file-options-schemas.test.js +0 -23
  233. package/dist/joint-file-types-legacy.js +0 -278
  234. package/dist/joint-file-types-legacy.test.js +0 -400
  235. package/dist/joint-file-types.js +0 -148
  236. package/dist/joint-file-types.test.js +0 -139
  237. package/dist/loader-registry.js +0 -98
  238. package/dist/plugins.js +0 -154
  239. package/dist/plugins.test.js +0 -30
  240. package/dist/schemas/PrettyJsonSchema.js +0 -34
  241. package/dist/schemas/config-1.0.15.schema.test.js +0 -22
  242. package/dist/schemas/config-1.0.16.schema.test.js +0 -22
  243. package/dist/schemas/obs-sets-tabular.schema.js +0 -37
  244. package/dist/schemas/obs-sets.schema.js +0 -194
  245. package/dist/schemas/schema.test-old.js +0 -50
  246. package/dist/schemas/schema.test.js +0 -46
  247. package/dist/schemas-extra.js +0 -3
  248. package/dist/schemas.js +0 -4
  249. package/dist/shared-plot-options/index.js +0 -4
  250. package/dist/view-config-upgraders.js +0 -525
  251. package/dist/view-config-utils.test.js +0 -66
  252. package/dist/view-config-versions.js +0 -47
  253. package/dist/vitessce-grid-layout/index.js +0 -1
  254. /package/{dist → dist-tsc}/classNames.js +0 -0
  255. /package/{dist → dist-tsc}/data/LoaderResult.js +0 -0
  256. /package/{dist → dist-tsc}/errors/AbstractLoaderError.js +0 -0
  257. /package/{dist → dist-tsc}/plugins.test.fixtures.js +0 -0
  258. /package/{dist → dist-tsc}/schemas/config-0.1.0.schema.json +0 -0
  259. /package/{dist → dist-tsc}/schemas/config-1.0.0.schema.json +0 -0
  260. /package/{dist → dist-tsc}/schemas/config-1.0.1.schema.json +0 -0
  261. /package/{dist → dist-tsc}/schemas/config-1.0.10.schema.json +0 -0
  262. /package/{dist → dist-tsc}/schemas/config-1.0.11.schema.json +0 -0
  263. /package/{dist → dist-tsc}/schemas/config-1.0.12.schema.json +0 -0
  264. /package/{dist → dist-tsc}/schemas/config-1.0.13.schema.json +0 -0
  265. /package/{dist → dist-tsc}/schemas/config-1.0.14.schema.json +0 -0
  266. /package/{dist → dist-tsc}/schemas/config-1.0.15.schema.json +0 -0
  267. /package/{dist → dist-tsc}/schemas/config-1.0.2.schema.json +0 -0
  268. /package/{dist → dist-tsc}/schemas/config-1.0.3.schema.json +0 -0
  269. /package/{dist → dist-tsc}/schemas/config-1.0.4.schema.json +0 -0
  270. /package/{dist → dist-tsc}/schemas/config-1.0.5.schema.json +0 -0
  271. /package/{dist → dist-tsc}/schemas/config-1.0.6.schema.json +0 -0
  272. /package/{dist → dist-tsc}/schemas/config-1.0.7.schema.json +0 -0
  273. /package/{dist → dist-tsc}/schemas/config-1.0.8.schema.json +0 -0
  274. /package/{dist → dist-tsc}/schemas/config-1.0.9.schema.json +0 -0
  275. /package/{dist → dist-tsc}/schemas/obsSets.schema.js +0 -0
  276. /package/{dist → dist-tsc}/schemas/obsSetsTabular.schema.js +0 -0
  277. /package/{dist → dist-tsc}/schemas/raster.schema.js +0 -0
@@ -0,0 +1,118 @@
1
+ import React, {
2
+ useEffect,
3
+ useCallback,
4
+ } from 'react';
5
+ import clsx from 'clsx';
6
+ import { VITESSCE_CONTAINER } from './classNames.js';
7
+ import { VitessceGridLayout } from './vitessce-grid-layout/index.js';
8
+ import { useRowHeight, createLoaders } from './vitessce-grid-utils.js';
9
+ import {
10
+ useViewConfigStoreApi,
11
+ useSetViewConfig,
12
+ useSetLoaders,
13
+ useEmitGridResize,
14
+ useRemoveComponent,
15
+ useChangeLayout,
16
+ useLayout,
17
+ } from './state/hooks.js';
18
+ import {
19
+ useClosestVitessceContainerSize,
20
+ } from './hooks.js';
21
+ import { useVitessceContainerStyles } from './shared-mui/container.js';
22
+ import { useTitleStyles } from './title-styles.js';
23
+
24
+ const padding = 10;
25
+ const margin = 5;
26
+
27
+ /**
28
+ * The wrapper for the VitessceGrid and LoadingIndicator components.
29
+ * @param {object} props
30
+ * @param {number} props.rowHeight The height of each grid row. Optional.
31
+ * @param {object} props.config The view config.
32
+ * @param {string} props.theme The theme name.
33
+ * @param {number} props.height Total height for grid. Optional.
34
+ * @param {function} props.onWarn A callback for warning messages. Optional.
35
+ * @param {PluginViewType[]} props.viewTypes
36
+ * @param {PluginFileType[]} props.fileTypes
37
+ * @param {PluginCoordinationType[]} props.coordinationTypes
38
+ */
39
+ export default function VitessceGrid(props) {
40
+ const {
41
+ rowHeight: initialRowHeight,
42
+ config,
43
+ theme,
44
+ height,
45
+ isBounded,
46
+ viewTypes,
47
+ fileTypes,
48
+ coordinationTypes,
49
+ } = props;
50
+
51
+ const [rowHeight, containerRef] = useRowHeight(config, initialRowHeight, height, margin, padding);
52
+ const onResize = useEmitGridResize();
53
+
54
+ const [componentWidth] = useClosestVitessceContainerSize(containerRef);
55
+
56
+ const classes = useVitessceContainerStyles();
57
+ const titleClasses = useTitleStyles();
58
+
59
+ // When the row height has changed, publish a GRID_RESIZE event.
60
+ useEffect(() => {
61
+ onResize();
62
+ }, [rowHeight, onResize]);
63
+
64
+ const viewConfigStoreApi = useViewConfigStoreApi();
65
+ const setViewConfig = useSetViewConfig(viewConfigStoreApi);
66
+ const setLoaders = useSetLoaders();
67
+ const removeComponent = useRemoveComponent();
68
+ const changeLayout = useChangeLayout();
69
+ const layout = useLayout();
70
+
71
+ const changeLayoutPostMount = useCallback((newComponentProps) => {
72
+ if (componentWidth > 0) {
73
+ changeLayout(newComponentProps);
74
+ }
75
+ }, [changeLayout, componentWidth]);
76
+
77
+ // Update the view config and loaders in the global state.
78
+ useEffect(() => {
79
+ if (config) {
80
+ setViewConfig(config);
81
+ const loaders = createLoaders(
82
+ config.datasets,
83
+ config.description,
84
+ fileTypes,
85
+ coordinationTypes,
86
+ );
87
+ setLoaders(loaders);
88
+ } else {
89
+ // No config found, so clear the loaders.
90
+ setLoaders({});
91
+ }
92
+ }, [config, setViewConfig, setLoaders, fileTypes, coordinationTypes]);
93
+
94
+ return (
95
+ <div
96
+ ref={containerRef}
97
+ className={clsx(VITESSCE_CONTAINER, classes.vitessceContainer)}
98
+ >
99
+ {layout && (
100
+ <VitessceGridLayout
101
+ layout={layout}
102
+ height={height}
103
+ rowHeight={rowHeight}
104
+ theme={theme}
105
+ viewTypes={viewTypes}
106
+ draggableHandle={titleClasses.title}
107
+ margin={margin}
108
+ padding={padding}
109
+ onRemoveComponent={removeComponent}
110
+ onLayoutChange={changeLayoutPostMount}
111
+ isBounded={isBounded}
112
+ onResize={onResize}
113
+ onResizeStop={onResize}
114
+ />
115
+ )}
116
+ </div>
117
+ );
118
+ }
@@ -0,0 +1,57 @@
1
+ import '@testing-library/jest-dom';
2
+ import { cleanup, render, screen } from '@testing-library/react';
3
+ import { afterEach } from 'vitest';
4
+
5
+ import React from 'react';
6
+ import { PluginViewType } from '@vitessce/plugins';
7
+ import VitessceGrid from './VitessceGrid.js';
8
+ import {
9
+ ViewConfigProvider, createViewConfigStore,
10
+ AuxiliaryProvider, createAuxiliaryStore,
11
+ } from './state/hooks.js';
12
+
13
+ afterEach(() => {
14
+ cleanup();
15
+ });
16
+
17
+ describe('VitessceGrid.js', () => {
18
+ describe('<VitessceGrid />', () => {
19
+ it('renders', async () => {
20
+ const config = {
21
+ version: '1.0.0',
22
+ description: 'fake description',
23
+ datasets: [],
24
+ name: 'fake name',
25
+ layout: [
26
+ {
27
+ component: 'FakeComponent',
28
+ props: { description: 'fake prop description' },
29
+ uid: 'A',
30
+ x: 0,
31
+ y: 0,
32
+ },
33
+ ],
34
+ };
35
+
36
+ function FakeComponent() {
37
+ return <p>FakeComponent!</p>;
38
+ }
39
+ const viewTypes = [new PluginViewType('FakeComponent', FakeComponent, [])];
40
+ const fileTypes = [];
41
+ const coordinationTypes = [];
42
+ render(
43
+ <ViewConfigProvider createStore={createViewConfigStore}>
44
+ <AuxiliaryProvider createStore={createAuxiliaryStore}>
45
+ <VitessceGrid
46
+ config={config}
47
+ viewTypes={viewTypes}
48
+ fileTypes={fileTypes}
49
+ coordinationTypes={coordinationTypes}
50
+ />
51
+ </AuxiliaryProvider>
52
+ </ViewConfigProvider>,
53
+ );
54
+ expect(await screen.findByText('FakeComponent!'));
55
+ });
56
+ });
57
+ });
package/src/Warning.js ADDED
@@ -0,0 +1,62 @@
1
+ import clsx from 'clsx';
2
+ import { makeStyles } from '@material-ui/core';
3
+ import { VITESSCE_CONTAINER } from './classNames.js';
4
+
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: '12px',
28
+ marginTop: '8px',
29
+ marginBottom: '8px',
30
+ position: 'relative',
31
+ display: 'flex',
32
+ flexDirection: 'column',
33
+ minWidth: '0',
34
+ wordWrap: 'break-word',
35
+ backgroundClip: 'border-box',
36
+ borderRadius: '4px',
37
+ backgroundColor: theme.palette.primaryBackground,
38
+ color: theme.palette.primaryForeground,
39
+ },
40
+ }));
41
+
42
+ export function Warning(props) {
43
+ const {
44
+ title,
45
+ preformatted,
46
+ unformatted,
47
+ } = props;
48
+ const classes = useStyles();
49
+ return (
50
+ <div className={VITESSCE_CONTAINER}>
51
+ <div className={clsx(classes.warningLayout, classes.containerFluid)}>
52
+ <div className={classes.row}>
53
+ <div className={classes.card}>
54
+ <h1>{title}</h1>
55
+ {preformatted ? (<pre>{preformatted}</pre>) : null}
56
+ <p>{unformatted}</p>
57
+ </div>
58
+ </div>
59
+ </div>
60
+ </div>
61
+ );
62
+ }
@@ -0,0 +1,8 @@
1
+ export const TOOLTIP_ANCESTOR = 'tooltip-ancestor';
2
+ const CARD = `card card-body my-2 ${TOOLTIP_ANCESTOR}`;
3
+ export const PRIMARY_CARD = `${CARD} bg-primary`;
4
+ export const SECONDARY_CARD = `${CARD} bg-secondary`;
5
+ export const BLACK_CARD = `${CARD} bg-black`;
6
+ export const TITLE_CARD = 'title';
7
+ export const SCROLL_CARD = `${PRIMARY_CARD} scroll`;
8
+ export const VITESSCE_CONTAINER = 'vitessce-container';
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A loader ancestor class containing a default constructor
3
+ * and a stub for the required load() method.
4
+ */
5
+ export default class AbstractLoader {
6
+ constructor({
7
+ type, fileType,
8
+ url, requestInit,
9
+ options, coordinationValues,
10
+ }) {
11
+ this.fileType = fileType;
12
+ this.type = type;
13
+ this.url = url;
14
+ this.requestInit = requestInit;
15
+ this.options = options;
16
+ this.coordinationValues = coordinationValues;
17
+ }
18
+
19
+ // eslint-disable-next-line class-methods-use-this
20
+ load() {
21
+ return Promise.resolve(true);
22
+ }
23
+ }
@@ -0,0 +1,8 @@
1
+ import AbstractLoader from './AbstractLoader.js';
2
+
3
+ export default class AbstractTwoStepLoader extends AbstractLoader {
4
+ constructor(dataSource, params) {
5
+ super(params);
6
+ this.dataSource = dataSource;
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+
2
+ export default class LoaderResult {
3
+ constructor(data, url, coordinationValues = null) {
4
+ this.data = data;
5
+ this.url = url;
6
+ this.coordinationValues = coordinationValues;
7
+ }
8
+ }
@@ -0,0 +1,3 @@
1
+ export { default as AbstractLoader } from './AbstractLoader.js';
2
+ export { default as AbstractTwoStepLoader } from './AbstractTwoStepLoader.js';
3
+ export { default as LoaderResult } from './LoaderResult.js';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Get the data source and data loader class.
3
+ * @param {string} type The fileType name.
4
+ * @param {PluginFileType[]} fileTypes The array of file types.
5
+ * @returns {array} [dataSourceClass, dataLoaderClass].
6
+ */
7
+ export function getSourceAndLoaderFromFileType(type, fileTypes) {
8
+ if (Array.isArray(fileTypes)) {
9
+ const matchingFileType = fileTypes.find(ft => ft.name === type);
10
+ if (matchingFileType) {
11
+ return matchingFileType.getSourceAndLoader();
12
+ }
13
+ }
14
+ // Fallback to JSON.
15
+ // TODO(monorepo)
16
+ // return [JsonSource, JsonLoader];
17
+ return [null, null];
18
+ }
19
+
20
+ export function getDataTypeFromFileType(type, fileTypes) {
21
+ if (Array.isArray(fileTypes)) {
22
+ const matchingFileType = fileTypes.find(ft => ft.name === type);
23
+ if (matchingFileType) {
24
+ return matchingFileType.dataType;
25
+ }
26
+ }
27
+ return null;
28
+ }
@@ -0,0 +1,195 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { capitalize } from '@vitessce/utils';
3
+ import { STATUS } from '@vitessce/constants-internal';
4
+ import { useMatchingLoader, useMatchingLoaders, useSetWarning } from './state/hooks.js';
5
+ import {
6
+ AbstractLoaderError,
7
+ LoaderNotFoundError,
8
+ } from './errors/index.js';
9
+
10
+ /**
11
+ * Warn via publishing to the console
12
+ * and to the global warning store.
13
+ * @param {AbstractLoaderError} error An error instance.
14
+ */
15
+ export function warn(error, setWarning) {
16
+ setWarning(error.message);
17
+ console.warn(error.message);
18
+ console.error(error.stack);
19
+ if (error instanceof AbstractLoaderError) {
20
+ error.warnInConsole();
21
+ }
22
+ }
23
+
24
+ /**
25
+ * Initialize values in the coordination space.
26
+ * @param {object} values Object where
27
+ * keys are coordination type names,
28
+ * values are initial coordination values.
29
+ * @param {object} setters Object where
30
+ * keys are coordination type names with the prefix 'set',
31
+ * values are coordination setter functions.
32
+ * @param {object} initialValues Object where
33
+ * keys are coordination type names and keys are values.
34
+ */
35
+ export function initCoordinationSpace(values, setters, initialValues) {
36
+ if (!values || !setters) {
37
+ return;
38
+ }
39
+ Object.entries(values).forEach(([coordinationType, value]) => {
40
+ const setterName = `set${capitalize(coordinationType)}`;
41
+ const setterFunc = setters[setterName];
42
+ const initialValue = initialValues && initialValues[coordinationType];
43
+ // Interpret null as "uninitialized" and therefore needing initialization.
44
+ const shouldInit = initialValue === null;
45
+ if (shouldInit && setterFunc) {
46
+ setterFunc(value);
47
+ }
48
+ });
49
+ }
50
+
51
+
52
+ /**
53
+ * Get data from a cells data type loader,
54
+ * updating "ready" and URL state appropriately.
55
+ * Throw warnings if the data is marked as required.
56
+ * Subscribe to loader updates.
57
+ * @param {object} loaders The object mapping
58
+ * datasets and data types to loader instances.
59
+ * @param {string} dataset The key for a dataset,
60
+ * used to identify which loader to use.
61
+ * @param {function} addUrl A function to call to update
62
+ * the URL list.
63
+ * @param {boolean} isRequired Should a warning be thrown if
64
+ * loading is unsuccessful?
65
+ * @param {object} coordinationSetters Object where
66
+ * keys are coordination type names with the prefix 'set',
67
+ * values are coordination setter functions.
68
+ * @param {object} initialCoordinationValues Object where
69
+ * keys are coordination type names with the prefix 'initialize',
70
+ * values are initialization preferences as boolean values.
71
+ * @returns {array} [cells, cellsCount] where
72
+ * cells is an object and cellsCount is the
73
+ * number of items in the cells object.
74
+ */
75
+ export function useDataType(
76
+ dataType, loaders, dataset, addUrl, isRequired,
77
+ coordinationSetters, initialCoordinationValues, matchOn,
78
+ ) {
79
+ const [data, setData] = useState({});
80
+ const [status, setStatus] = useState(STATUS.LOADING);
81
+
82
+ const setWarning = useSetWarning();
83
+ const loader = useMatchingLoader(loaders, dataset, dataType, matchOn);
84
+
85
+ useEffect(() => {
86
+ if (loader) {
87
+ setStatus(STATUS.LOADING);
88
+ loader.load().catch(e => warn(e, setWarning)).then((payload) => {
89
+ if (!payload) return;
90
+ const { data: payloadData, url, coordinationValues } = payload;
91
+ setData(payloadData);
92
+ if (Array.isArray(url)) {
93
+ url.forEach(([val, name]) => {
94
+ addUrl(val, name);
95
+ });
96
+ } else if (url) {
97
+ addUrl(url, dataType);
98
+ }
99
+ initCoordinationSpace(
100
+ coordinationValues,
101
+ coordinationSetters,
102
+ initialCoordinationValues,
103
+ );
104
+ setStatus(STATUS.SUCCESS);
105
+ });
106
+ } else {
107
+ setData({});
108
+ if (isRequired) {
109
+ warn(new LoaderNotFoundError(loaders, dataset, dataType, matchOn), setWarning);
110
+ setStatus(STATUS.ERROR);
111
+ } else {
112
+ setStatus(STATUS.SUCCESS);
113
+ }
114
+ }
115
+ // eslint-disable-next-line react-hooks/exhaustive-deps
116
+ }, [loader]);
117
+
118
+ return [data, status];
119
+ }
120
+
121
+ /**
122
+ * Get data from a cells data type loader,
123
+ * updating "ready" and URL state appropriately.
124
+ * Throw warnings if the data is marked as required.
125
+ * Subscribe to loader updates.
126
+ * @param {object} loaders The object mapping
127
+ * datasets and data types to loader instances.
128
+ * @param {string} dataset The key for a dataset,
129
+ * used to identify which loader to use.
130
+ * @param {function} addUrl A function to call to update
131
+ * the URL list.
132
+ * @param {boolean} isRequired Should a warning be thrown if
133
+ * loading is unsuccessful?
134
+ * @param {object} coordinationSetters Object where
135
+ * keys are coordination type names with the prefix 'set',
136
+ * values are coordination setter functions.
137
+ * @param {object} initialCoordinationValues Object where
138
+ * keys are coordination type names with the prefix 'initialize',
139
+ * values are initialization preferences as boolean values.
140
+ * @returns {array} [cells, cellsCount] where
141
+ * cells is an object and cellsCount is the
142
+ * number of items in the cells object.
143
+ */
144
+ export function useDataTypeMulti(
145
+ dataType, loaders, dataset, addUrl, isRequired,
146
+ coordinationSetters, initialCoordinationValues, matchOnObj,
147
+ ) {
148
+ const [data, setData] = useState({});
149
+ const [status, setStatus] = useState(STATUS.LOADING);
150
+
151
+ const setWarning = useSetWarning();
152
+ const matchingLoaders = useMatchingLoaders(loaders, dataset, dataType, matchOnObj);
153
+
154
+ useEffect(() => {
155
+ if (matchingLoaders) {
156
+ setStatus(STATUS.LOADING);
157
+ Object.entries(matchingLoaders).forEach(([scopeKey, loader]) => {
158
+ if (loader) {
159
+ loader.load().catch(e => warn(e, setWarning)).then((payload) => {
160
+ if (!payload) return;
161
+ const { data: payloadData, url, coordinationValues } = payload;
162
+ setData((prev) => {
163
+ // eslint-disable-next-line no-param-reassign
164
+ prev[scopeKey] = payloadData;
165
+ return prev;
166
+ });
167
+ addUrl(url, dataType);
168
+ initCoordinationSpace(
169
+ coordinationValues,
170
+ coordinationSetters,
171
+ initialCoordinationValues,
172
+ );
173
+ setStatus(STATUS.SUCCESS);
174
+ });
175
+ }
176
+ });
177
+ } else {
178
+ setData({});
179
+ if (isRequired) {
180
+ warn(new LoaderNotFoundError(loaders, dataset, dataType, matchOnObj), setWarning);
181
+ setStatus(STATUS.ERROR);
182
+ } else {
183
+ setStatus(STATUS.SUCCESS);
184
+ }
185
+ }
186
+ // eslint-disable-next-line react-hooks/exhaustive-deps
187
+ }, [matchingLoaders]);
188
+
189
+ return [data, status];
190
+ }
191
+
192
+ export function useHasLoader(loaders, dataset, dataType, matchOn) {
193
+ const loader = useMatchingLoader(loaders, dataset, dataType, matchOn);
194
+ return loader !== null;
195
+ }