@vitessce/vit-s 2.0.3 → 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 (216) hide show
  1. package/dist/index.js +41348 -0
  2. package/dist-tsc/CallbackPublisher.d.ts +18 -0
  3. package/dist-tsc/CallbackPublisher.d.ts.map +1 -0
  4. package/dist-tsc/CallbackPublisher.js +62 -0
  5. package/dist-tsc/LoadingIndicator.d.ts +2 -0
  6. package/dist-tsc/LoadingIndicator.d.ts.map +1 -0
  7. package/dist-tsc/LoadingIndicator.js +26 -0
  8. package/dist-tsc/TitleInfo.d.ts +2 -0
  9. package/dist-tsc/TitleInfo.d.ts.map +1 -0
  10. package/dist-tsc/TitleInfo.js +74 -0
  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-tsc/VitessceGrid.js +60 -0
  17. package/dist-tsc/VitessceGrid.test.d.ts +2 -0
  18. package/dist-tsc/VitessceGrid.test.d.ts.map +1 -0
  19. package/dist-tsc/VitessceGrid.test.js +40 -0
  20. package/dist-tsc/Warning.d.ts +2 -0
  21. package/dist-tsc/Warning.d.ts.map +1 -0
  22. package/dist-tsc/Warning.js +45 -0
  23. package/dist-tsc/classNames.d.ts +8 -0
  24. package/dist-tsc/classNames.d.ts.map +1 -0
  25. package/dist-tsc/classNames.js +8 -0
  26. package/dist-tsc/data/AbstractLoader.d.ts +22 -0
  27. package/dist-tsc/data/AbstractLoader.d.ts.map +1 -0
  28. package/dist-tsc/data/AbstractLoader.js +18 -0
  29. package/dist-tsc/data/AbstractTwoStepLoader.d.ts +6 -0
  30. package/dist-tsc/data/AbstractTwoStepLoader.d.ts.map +1 -0
  31. package/dist-tsc/data/AbstractTwoStepLoader.js +7 -0
  32. package/dist-tsc/data/LoaderResult.d.ts +7 -0
  33. package/dist-tsc/data/LoaderResult.d.ts.map +1 -0
  34. package/dist-tsc/data/LoaderResult.js +7 -0
  35. package/dist-tsc/data/index.d.ts +4 -0
  36. package/dist-tsc/data/index.d.ts.map +1 -0
  37. package/dist-tsc/data/index.js +3 -0
  38. package/dist-tsc/data/loader-registry.d.ts +9 -0
  39. package/dist-tsc/data/loader-registry.d.ts.map +1 -0
  40. package/dist-tsc/data/loader-registry.js +27 -0
  41. package/dist-tsc/data-hook-utils.d.ts +69 -0
  42. package/dist-tsc/data-hook-utils.d.ts.map +1 -0
  43. package/dist-tsc/data-hook-utils.js +173 -0
  44. package/dist-tsc/data-hooks.d.ts +77 -0
  45. package/dist-tsc/data-hooks.d.ts.map +1 -0
  46. package/dist-tsc/data-hooks.js +241 -0
  47. package/dist-tsc/errors/AbstractLoaderError.d.ts +10 -0
  48. package/dist-tsc/errors/AbstractLoaderError.d.ts.map +1 -0
  49. package/dist-tsc/errors/AbstractLoaderError.js +13 -0
  50. package/dist-tsc/errors/DataSourceFetchError.d.ts +8 -0
  51. package/dist-tsc/errors/DataSourceFetchError.d.ts.map +1 -0
  52. package/dist-tsc/errors/DataSourceFetchError.js +13 -0
  53. package/dist-tsc/errors/DatasetNotFoundError.d.ts +6 -0
  54. package/dist-tsc/errors/DatasetNotFoundError.d.ts.map +1 -0
  55. package/dist-tsc/errors/DatasetNotFoundError.js +17 -0
  56. package/dist-tsc/errors/LoaderNotFoundError.d.ts +10 -0
  57. package/dist-tsc/errors/LoaderNotFoundError.d.ts.map +1 -0
  58. package/dist-tsc/errors/LoaderNotFoundError.js +17 -0
  59. package/dist-tsc/errors/LoaderValidationError.d.ts +10 -0
  60. package/dist-tsc/errors/LoaderValidationError.d.ts.map +1 -0
  61. package/dist-tsc/errors/LoaderValidationError.js +15 -0
  62. package/dist-tsc/errors/index.d.ts +6 -0
  63. package/dist-tsc/errors/index.d.ts.map +1 -0
  64. package/dist-tsc/errors/index.js +5 -0
  65. package/dist-tsc/hooks.d.ts +80 -0
  66. package/dist-tsc/hooks.d.ts.map +1 -0
  67. package/dist-tsc/hooks.js +271 -0
  68. package/dist-tsc/index.d.ts +11 -0
  69. package/dist-tsc/index.d.ts.map +1 -0
  70. package/dist-tsc/index.js +10 -17
  71. package/dist-tsc/plugins.test.fixtures.d.ts +61 -0
  72. package/dist-tsc/plugins.test.fixtures.d.ts.map +1 -0
  73. package/dist-tsc/plugins.test.fixtures.js +76 -0
  74. package/dist-tsc/schemas/config-0.1.0.schema.json +84 -0
  75. package/dist-tsc/schemas/config-1.0.0.schema.json +733 -0
  76. package/dist-tsc/schemas/config-1.0.1.schema.json +909 -0
  77. package/dist-tsc/schemas/config-1.0.10.schema.json +969 -0
  78. package/dist-tsc/schemas/config-1.0.11.schema.json +990 -0
  79. package/dist-tsc/schemas/config-1.0.12.schema.json +997 -0
  80. package/dist-tsc/schemas/config-1.0.13.schema.json +1013 -0
  81. package/dist-tsc/schemas/config-1.0.14.schema.json +1048 -0
  82. package/dist-tsc/schemas/config-1.0.15.schema.json +1048 -0
  83. package/dist-tsc/schemas/config-1.0.16.schema.json +1089 -0
  84. package/dist-tsc/schemas/config-1.0.2.schema.json +910 -0
  85. package/dist-tsc/schemas/config-1.0.3.schema.json +910 -0
  86. package/dist-tsc/schemas/config-1.0.4.schema.json +949 -0
  87. package/dist-tsc/schemas/config-1.0.5.schema.json +949 -0
  88. package/dist-tsc/schemas/config-1.0.6.schema.json +949 -0
  89. package/dist-tsc/schemas/config-1.0.7.schema.json +949 -0
  90. package/dist-tsc/schemas/config-1.0.8.schema.json +965 -0
  91. package/dist-tsc/schemas/config-1.0.9.schema.json +965 -0
  92. package/dist-tsc/schemas/obsSets.schema.d.ts +179 -0
  93. package/dist-tsc/schemas/obsSets.schema.d.ts.map +1 -0
  94. package/dist-tsc/schemas/obsSets.schema.js +195 -0
  95. package/dist-tsc/schemas/obsSetsTabular.schema.d.ts +57 -0
  96. package/dist-tsc/schemas/obsSetsTabular.schema.d.ts.map +1 -0
  97. package/dist-tsc/schemas/obsSetsTabular.schema.js +38 -0
  98. package/dist-tsc/schemas/raster.schema.d.ts +239 -0
  99. package/dist-tsc/schemas/raster.schema.d.ts.map +1 -0
  100. package/dist-tsc/schemas/raster.schema.js +120 -0
  101. package/dist-tsc/shared-mui/components.d.ts +2 -0
  102. package/dist-tsc/shared-mui/components.d.ts.map +1 -0
  103. package/dist-tsc/shared-mui/components.js +29 -0
  104. package/dist-tsc/shared-mui/container.d.ts +2 -0
  105. package/dist-tsc/shared-mui/container.d.ts.map +1 -0
  106. package/dist-tsc/shared-mui/container.js +211 -0
  107. package/dist-tsc/shared-mui/styles.d.ts +5 -0
  108. package/dist-tsc/shared-mui/styles.d.ts.map +1 -0
  109. package/dist-tsc/shared-mui/styles.js +109 -0
  110. package/dist-tsc/shared-plot-options/CellColorEncodingOption.d.ts +2 -0
  111. package/dist-tsc/shared-plot-options/CellColorEncodingOption.d.ts.map +1 -0
  112. package/dist-tsc/shared-plot-options/CellColorEncodingOption.js +17 -0
  113. package/dist-tsc/shared-plot-options/OptionSelect.d.ts +2 -0
  114. package/dist-tsc/shared-plot-options/OptionSelect.d.ts.map +1 -0
  115. package/dist-tsc/shared-plot-options/OptionSelect.js +12 -0
  116. package/dist-tsc/shared-plot-options/OptionsContainer.d.ts +2 -0
  117. package/dist-tsc/shared-plot-options/OptionsContainer.d.ts.map +1 -0
  118. package/dist-tsc/shared-plot-options/OptionsContainer.js +9 -0
  119. package/dist-tsc/shared-plot-options/index.d.ts +5 -0
  120. package/dist-tsc/shared-plot-options/index.d.ts.map +1 -0
  121. package/dist-tsc/shared-plot-options/index.js +4 -0
  122. package/dist-tsc/shared-plot-options/styles.d.ts +2 -0
  123. package/dist-tsc/shared-plot-options/styles.d.ts.map +1 -0
  124. package/dist-tsc/shared-plot-options/styles.js +48 -0
  125. package/dist-tsc/state/hooks.d.ts +216 -0
  126. package/dist-tsc/state/hooks.d.ts.map +1 -0
  127. package/dist-tsc/state/hooks.js +575 -0
  128. package/dist-tsc/title-styles.d.ts +2 -0
  129. package/dist-tsc/title-styles.d.ts.map +1 -0
  130. package/dist-tsc/title-styles.js +72 -0
  131. package/dist-tsc/view-config-utils.d.ts +30 -0
  132. package/dist-tsc/view-config-utils.d.ts.map +1 -0
  133. package/dist-tsc/view-config-utils.js +234 -0
  134. package/dist-tsc/view-config-utils.test.d.ts +2 -0
  135. package/dist-tsc/view-config-utils.test.d.ts.map +1 -0
  136. package/dist-tsc/view-config-utils.test.fixtures.d.ts +1049 -0
  137. package/dist-tsc/view-config-utils.test.fixtures.d.ts.map +1 -0
  138. package/dist-tsc/view-config-utils.test.fixtures.js +883 -0
  139. package/dist-tsc/view-config-utils.test.js +209 -0
  140. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.d.ts +8 -0
  141. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.d.ts.map +1 -0
  142. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.js +114 -0
  143. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.test.d.ts +2 -0
  144. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.test.d.ts.map +1 -0
  145. package/dist-tsc/vitessce-grid-layout/VitessceGridLayout.test.js +48 -0
  146. package/dist-tsc/vitessce-grid-layout/index.d.ts +2 -0
  147. package/dist-tsc/vitessce-grid-layout/index.d.ts.map +1 -0
  148. package/dist-tsc/vitessce-grid-layout/index.js +1 -0
  149. package/dist-tsc/vitessce-grid-layout/layout-utils.d.ts +15 -0
  150. package/dist-tsc/vitessce-grid-layout/layout-utils.d.ts.map +1 -0
  151. package/dist-tsc/vitessce-grid-layout/layout-utils.js +61 -0
  152. package/dist-tsc/vitessce-grid-layout/layout-utils.test.d.ts +2 -0
  153. package/dist-tsc/vitessce-grid-layout/layout-utils.test.d.ts.map +1 -0
  154. package/dist-tsc/vitessce-grid-layout/layout-utils.test.js +148 -0
  155. package/dist-tsc/vitessce-grid-utils.d.ts +13 -0
  156. package/dist-tsc/vitessce-grid-utils.d.ts.map +1 -0
  157. package/dist-tsc/vitessce-grid-utils.js +141 -0
  158. package/package.json +23 -10
  159. package/src/CallbackPublisher.js +7 -11
  160. package/src/LoadingIndicator.js +1 -2
  161. package/src/TitleInfo.js +12 -85
  162. package/src/VitS.js +72 -50
  163. package/src/VitessceGrid.js +21 -13
  164. package/src/VitessceGrid.test.jsx +16 -7
  165. package/src/Warning.js +2 -2
  166. package/src/data/AbstractLoader.js +2 -25
  167. package/src/data/AbstractTwoStepLoader.js +1 -1
  168. package/src/data/index.js +3 -3
  169. package/src/data/loader-registry.js +22 -13
  170. package/src/data-hook-utils.js +4 -6
  171. package/src/data-hooks.js +4 -4
  172. package/src/errors/DataSourceFetchError.js +1 -1
  173. package/src/errors/DatasetNotFoundError.js +1 -1
  174. package/src/errors/LoaderNotFoundError.js +1 -1
  175. package/src/errors/LoaderValidationError.js +1 -1
  176. package/src/errors/index.js +5 -6
  177. package/src/hooks.js +70 -5
  178. package/src/index.js +21 -46
  179. package/src/schemas/config-1.0.16.schema.json +21 -1
  180. package/src/shared-mui/components.js +10 -8
  181. package/src/shared-mui/container.js +1 -1
  182. package/src/shared-mui/styles.js +5 -2
  183. package/src/shared-plot-options/CellColorEncodingOption.js +3 -4
  184. package/src/shared-plot-options/OptionSelect.js +2 -2
  185. package/src/shared-plot-options/OptionsContainer.js +2 -5
  186. package/src/shared-plot-options/index.js +4 -4
  187. package/src/shared-plot-options/styles.js +1 -1
  188. package/src/state/hooks.js +10 -3
  189. package/src/title-styles.js +73 -0
  190. package/src/view-config-utils.js +46 -98
  191. package/src/view-config-utils.test.jsx +222 -0
  192. package/src/vitessce-grid-layout/VitessceGridLayout.js +51 -30
  193. package/src/vitessce-grid-layout/VitessceGridLayout.test.jsx +17 -9
  194. package/src/vitessce-grid-layout/index.js +1 -1
  195. package/src/vitessce-grid-layout/layout-utils.js +1 -1
  196. package/src/vitessce-grid-layout/layout-utils.test.js +1 -1
  197. package/src/vitessce-grid-utils.js +27 -15
  198. package/dist/index.mjs +0 -84801
  199. package/src/component-registry.js +0 -21
  200. package/src/errors/OptionsValidationError.js +0 -25
  201. package/src/file-options-schemas-legacy.js +0 -139
  202. package/src/file-options-schemas-legacy.test.js +0 -138
  203. package/src/file-options-schemas.js +0 -327
  204. package/src/file-options-schemas.test.js +0 -26
  205. package/src/joint-file-types-legacy.js +0 -298
  206. package/src/joint-file-types-legacy.test.js +0 -412
  207. package/src/joint-file-types.js +0 -171
  208. package/src/joint-file-types.test.js +0 -144
  209. package/src/json-schemas.js +0 -9
  210. package/src/plugins.js +0 -186
  211. package/src/plugins.test.js +0 -42
  212. package/src/schemas/config-1.0.16.schema.test.js +0 -32
  213. package/src/schemas/schema.test-old.js +0 -49
  214. package/src/view-config-upgraders.js +0 -628
  215. package/src/view-config-utils.test.js +0 -95
  216. package/src/view-config-versions.js +0 -68
@@ -0,0 +1,575 @@
1
+ /* eslint-disable react-refresh/only-export-components */
2
+ import { useRef, useCallback, useMemo } from 'react';
3
+ import create from 'zustand';
4
+ import createContext from 'zustand/context';
5
+ import shallow from 'zustand/shallow';
6
+ import { isMatch } from 'lodash-es';
7
+ import { CoordinationType } from '@vitessce/constants-internal';
8
+ import { fromEntries, capitalize } from '@vitessce/utils';
9
+ // Reference: https://github.com/pmndrs/zustand#react-context
10
+ // Reference: https://github.com/pmndrs/zustand/blob/e47ea03/tests/context.test.tsx#L60
11
+ const { Provider: ViewConfigProviderLocal, useStore: useViewConfigStoreLocal, useStoreApi: useViewConfigStoreApiLocal, } = createContext();
12
+ export const ViewConfigProvider = ViewConfigProviderLocal;
13
+ export const useViewConfigStore = useViewConfigStoreLocal;
14
+ export const useViewConfigStoreApi = useViewConfigStoreApiLocal;
15
+ const { Provider: AuxiliaryProviderLocal, useStore: useAuxiliaryStoreLocal, } = createContext();
16
+ export const AuxiliaryProvider = AuxiliaryProviderLocal;
17
+ export const useAuxiliaryStore = useAuxiliaryStoreLocal;
18
+ /**
19
+ * The useViewConfigStore hook is initialized via the zustand
20
+ * create() function, which sets up both the state variables
21
+ * and the reducer-type functions.
22
+ * References:
23
+ * - https://github.com/react-spring/zustand
24
+ * - https://github.com/pmndrs/zustand/releases/tag/v3.6.0
25
+ * - https://github.com/pmndrs/zustand#using-subscribe-with-selector
26
+ * @returns {function} The useStore hook.
27
+ */
28
+ export const createViewConfigStore = () => create(set => ({
29
+ // State:
30
+ // The viewConfig is an object which must conform to the schema
31
+ // found in src/schemas/config.schema.json.
32
+ viewConfig: null,
33
+ // The loaders object is a mapping from dataset ID to
34
+ // data type to loader object instance.
35
+ loaders: null,
36
+ // Reducer functions which update the state
37
+ // (although technically also part of state):
38
+ setViewConfig: viewConfig => set({ viewConfig }),
39
+ setLoaders: loaders => set({ loaders }),
40
+ setCoordinationValue: ({ parameter, scope, value }) => set(state => ({
41
+ viewConfig: {
42
+ ...state.viewConfig,
43
+ coordinationSpace: {
44
+ ...state.viewConfig.coordinationSpace,
45
+ [parameter]: {
46
+ ...state.viewConfig.coordinationSpace[parameter],
47
+ [scope]: value,
48
+ },
49
+ },
50
+ },
51
+ })),
52
+ removeComponent: uid => set((state) => {
53
+ const newLayout = state.viewConfig.layout.filter(c => c.uid !== uid);
54
+ return {
55
+ viewConfig: {
56
+ ...state.viewConfig,
57
+ layout: newLayout,
58
+ },
59
+ };
60
+ }),
61
+ changeLayout: newComponentProps => set((state) => {
62
+ const newLayout = state.viewConfig.layout
63
+ .slice()
64
+ .map(componentProps => ({
65
+ ...componentProps,
66
+ ...newComponentProps[componentProps.uid],
67
+ }));
68
+ return {
69
+ viewConfig: {
70
+ ...state.viewConfig,
71
+ layout: newLayout,
72
+ },
73
+ };
74
+ }),
75
+ }));
76
+ /**
77
+ * Hook for getting components' layout from the view config based on
78
+ * matching all coordination scopes.
79
+ * @returns {Object} The components' layout.
80
+ */
81
+ export const useComponentLayout = (component, scopes, coordinationScopes) => useViewConfigStore(state => state.viewConfig.layout.filter(l => l.component === component).filter(l => scopes.every(scope => l.coordinationScopes[scope]
82
+ === coordinationScopes[scope])));
83
+ /**
84
+ * The useAuxiliaryStore hook is initialized via the zustand
85
+ * create() function, which sets up both the state variables
86
+ * and the reducer-type functions.
87
+ * Reference: https://github.com/react-spring/zustand
88
+ * It is meant to be used for non-viewconfig-based coordination between components.
89
+ * For example, as currently happens, the layer controller can coordinate
90
+ * on-load callbacks with spatial view based on whether or not they are
91
+ * coordinated via `spatialImageLayer` - the callbacks are not part of the view config
92
+ * though so they live here.
93
+ * @returns {function} The useStore hook.
94
+ */
95
+ export const createAuxiliaryStore = () => create(set => ({
96
+ auxiliaryStore: null,
97
+ setCoordinationValue: ({ parameter, scope, value }) => set(state => ({
98
+ auxiliaryStore: {
99
+ ...state.auxiliaryStore,
100
+ [parameter]: {
101
+ [scope]: value,
102
+ },
103
+ },
104
+ })),
105
+ }));
106
+ /**
107
+ * The hover store can be used to store global state
108
+ * related to which component is currently hovered,
109
+ * which is required for tooltip / crossover elements.
110
+ * @returns {function} The useStore hook.
111
+ */
112
+ const useHoverStore = create(set => ({
113
+ // Components may need to know if they are the "hover source"
114
+ // for tooltip interactions. This value should be a unique
115
+ // component ID, such as its index in the view config layout.
116
+ componentHover: null,
117
+ setComponentHover: componentHover => set({ componentHover }),
118
+ }));
119
+ /**
120
+ * The warning store can be used to store global state
121
+ * related to app warning messages.
122
+ * @returns {function} The useStore hook.
123
+ */
124
+ const useWarnStore = create(set => ({
125
+ // Want a global state to collect warning messages
126
+ // that occur anywhere in the app.
127
+ warning: null,
128
+ setWarning: warning => set({ warning }),
129
+ }));
130
+ /**
131
+ * The view info store can be used to store component-level
132
+ * viewInfo objects,
133
+ * which are required for tooltip / crossover elements.
134
+ * @returns {function} The useStore hook.
135
+ */
136
+ const useViewInfoStore = create(set => ({
137
+ // The viewInfo object is a mapping from
138
+ // component IDs to component view info objects.
139
+ // Each view info object must have a project() function.
140
+ viewInfo: {},
141
+ setComponentViewInfo: (uuid, viewInfo) => set(state => ({
142
+ viewInfo: {
143
+ ...state.viewInfo,
144
+ [uuid]: viewInfo,
145
+ },
146
+ })),
147
+ }));
148
+ /**
149
+ * The grid size store can be used to store a
150
+ * counter which updates on each window or react-grid-layout
151
+ * resize event.
152
+ * @returns {function} The useStore hook.
153
+ */
154
+ const useGridSizeStore = create(set => ({
155
+ resizeCount: {},
156
+ incrementResizeCount: () => set(state => ({
157
+ resizeCount: state.resizeCount + 1,
158
+ })),
159
+ }));
160
+ /**
161
+ * The useCoordination hook returns both the
162
+ * values and setter functions for the coordination objects
163
+ * in a particular coordination scope mapping.
164
+ * This hook is intended to be used within the ___Subscriber
165
+ * components to allow them to "hook into" only those coordination
166
+ * objects and setter functions of relevance.
167
+ * @param {string[]} parameters Array of coordination types.
168
+ * @param {object} coordinationScopes Mapping of coordination types
169
+ * to scope names.
170
+ * @returns {array} Returns a tuple [values, setters]
171
+ * where values is an object containing all coordination values,
172
+ * and setters is an object containing all coordination setter
173
+ * functions for the values in `values`, named with a "set"
174
+ * prefix.
175
+ */
176
+ export function useCoordination(parameters, coordinationScopes) {
177
+ const setCoordinationValue = useViewConfigStore(state => state.setCoordinationValue);
178
+ const values = useViewConfigStore((state) => {
179
+ const { coordinationSpace } = state.viewConfig;
180
+ return fromEntries(parameters.map((parameter) => {
181
+ if (coordinationSpace && coordinationSpace[parameter]) {
182
+ const value = coordinationSpace[parameter][coordinationScopes[parameter]];
183
+ return [parameter, value];
184
+ }
185
+ return [parameter, undefined];
186
+ }));
187
+ }, shallow);
188
+ const setters = useMemo(() => fromEntries(parameters.map((parameter) => {
189
+ const setterName = `set${capitalize(parameter)}`;
190
+ const setterFunc = value => setCoordinationValue({
191
+ parameter,
192
+ scope: coordinationScopes[parameter],
193
+ value,
194
+ });
195
+ return [setterName, setterFunc];
196
+ // eslint-disable-next-line react-hooks/exhaustive-deps
197
+ })), [parameters, coordinationScopes]);
198
+ return [values, setters];
199
+ }
200
+ export function useMultiCoordinationValues(parameter, coordinationScopes) {
201
+ const scopes = coordinationScopes[parameter];
202
+ // Mapping from dataset coordination scope name to dataset uid
203
+ const vals = useViewConfigStore((state) => {
204
+ const { coordinationSpace } = state.viewConfig;
205
+ // Convert a single scope to an array of scopes to be consistent.
206
+ const scopesArr = Array.isArray(scopes) ? scopes : [scopes];
207
+ return fromEntries(scopesArr.map((scope) => {
208
+ if (coordinationSpace && coordinationSpace[parameter]) {
209
+ const value = coordinationSpace[parameter][scope];
210
+ return [scope, value];
211
+ }
212
+ return [scope, undefined];
213
+ // eslint-disable-next-line no-unused-vars
214
+ }).filter(([k, v]) => v !== undefined));
215
+ }, shallow);
216
+ return vals;
217
+ }
218
+ /**
219
+ * Get a mapping from dataset coordination scopes to dataset UIDs.
220
+ * @param {object} coordinationScopes The coordination scope mapping object for a view.
221
+ * @returns {object} Mapping from dataset coordination scope names to dataset UIDs.
222
+ */
223
+ export function useDatasetUids(coordinationScopes) {
224
+ return useMultiCoordinationValues(CoordinationType.DATASET, coordinationScopes);
225
+ }
226
+ /**
227
+ * Use coordination values and coordination setter functions corresponding to
228
+ * {coordinationType}-specific coordination scopes for each coordination type.
229
+ * @param {string[]} parameters An array of coordination types supported by a view.
230
+ * @param {object} coordinationScopes The coordination scope mapping object for a view.
231
+ * @param {object} coordinationScopesBy The per-coordinationType coordination scope
232
+ * mapping object for a view.
233
+ * @param {string} byType The {coordinationType} to use for per-{coordinationType} coordination
234
+ * scope mappings.
235
+ * @returns {array} [cValues, cSetters] where
236
+ * cValues is a mapping from coordination scope name to { coordinationType: coordinationValue },
237
+ * and cSetters is a mapping from coordination scope name to { setCoordinationType }
238
+ * setter functions.
239
+ */
240
+ export function useComplexCoordination(parameters, coordinationScopes, coordinationScopesBy, byType) {
241
+ const setCoordinationValue = useViewConfigStore(state => state.setCoordinationValue);
242
+ const typeScopes = coordinationScopes[byType];
243
+ const byTypeScopes = coordinationScopesBy[byType];
244
+ // Convert a single scope to an array of scopes to be consistent.
245
+ const typeScopesArr = Array.isArray(typeScopes) ? typeScopes : [typeScopes];
246
+ const values = useViewConfigStore((state) => {
247
+ const { coordinationSpace } = state.viewConfig;
248
+ return fromEntries(typeScopesArr.map((datasetScope) => {
249
+ const datasetValues = fromEntries(parameters.map((parameter) => {
250
+ if (coordinationSpace && coordinationSpace[parameter]) {
251
+ let value;
252
+ const parameterSpace = coordinationSpace[parameter];
253
+ const parameterScopeGlobal = coordinationScopes[parameter];
254
+ const parameterScopeByDataset = byTypeScopes?.[parameter];
255
+ if (parameterScopeByDataset && parameterScopeByDataset[datasetScope]) {
256
+ value = parameterSpace[parameterScopeByDataset[datasetScope]];
257
+ }
258
+ else if (parameterScopeGlobal) {
259
+ value = parameterSpace[parameterScopeGlobal];
260
+ }
261
+ else {
262
+ console.error(`coordination scope for ${parameter} was not found.`);
263
+ }
264
+ return [parameter, value];
265
+ }
266
+ return [parameter, undefined];
267
+ }));
268
+ return [datasetScope, datasetValues];
269
+ }));
270
+ }, shallow);
271
+ const setters = useMemo(() => fromEntries(typeScopesArr.map((datasetScope) => {
272
+ const datasetSetters = fromEntries(parameters.map((parameter) => {
273
+ const setterName = `set${capitalize(parameter)}`;
274
+ let setterFunc;
275
+ const parameterScopeGlobal = coordinationScopes[parameter];
276
+ const parameterScopeByDataset = byTypeScopes?.[parameter];
277
+ if (parameterScopeByDataset && parameterScopeByDataset[datasetScope]) {
278
+ setterFunc = value => setCoordinationValue({
279
+ parameter,
280
+ scope: parameterScopeByDataset[datasetScope],
281
+ value,
282
+ });
283
+ }
284
+ else if (parameterScopeGlobal) {
285
+ setterFunc = value => setCoordinationValue({
286
+ parameter,
287
+ scope: parameterScopeGlobal,
288
+ value,
289
+ });
290
+ }
291
+ else {
292
+ console.error(`coordination scope for ${parameter} was not found.`);
293
+ }
294
+ return [setterName, setterFunc];
295
+ }));
296
+ return [datasetScope, datasetSetters];
297
+ // eslint-disable-next-line react-hooks/exhaustive-deps
298
+ })), [parameters, coordinationScopes]);
299
+ return [values, setters];
300
+ }
301
+ /**
302
+ * Use coordination values and coordination setter functions corresponding to
303
+ * dataset-specific coordination scopes for each coordination type.
304
+ * @param {string[]} parameters An array of coordination types supported by a view.
305
+ * @param {object} coordinationScopes The coordination scope mapping object for a view.
306
+ * @param {object} coordinationScopesBy The per-coordinationType coordination scope
307
+ * mapping object for a view.
308
+ * @returns {array} [cValues, cSetters] where
309
+ * cValues is a mapping from coordination scope name to { coordinationType: coordinationValue },
310
+ * and cSetters is a mapping from coordination scope name to { setCoordinationType }
311
+ * setter functions.
312
+ */
313
+ export function useMultiDatasetCoordination(parameters, coordinationScopes, coordinationScopesBy) {
314
+ return useComplexCoordination(parameters, coordinationScopes, coordinationScopesBy, CoordinationType.DATASET);
315
+ }
316
+ const AUXILIARY_COORDINATION_TYPES_MAP = {
317
+ spatialImageLayer: ['imageLayerCallbacks', 'areLoadingImageChannels'],
318
+ spatialSegmentationLayer: ['segmentationLayerCallbacks', 'areLoadingSegmentationChannels'],
319
+ };
320
+ /**
321
+ * The maps the coordination types of incoming scopes to new types
322
+ * for the auxiliary store.
323
+ * @param {object} coordinationScopes Mapping of coordination types
324
+ * to scope names.
325
+ * @returns {object} Mapping of coordination types
326
+ * to new scope names for the auxiliary store.
327
+ */
328
+ const mapCoordinationScopes = (coordinationScopes) => {
329
+ const newCoordinationScopes = {};
330
+ Object.keys(coordinationScopes).forEach((key) => {
331
+ const newCoordinationTypes = AUXILIARY_COORDINATION_TYPES_MAP[key] || [];
332
+ newCoordinationTypes.forEach((coordinationType) => {
333
+ newCoordinationScopes[coordinationType || key] = coordinationScopes[key];
334
+ });
335
+ });
336
+ return newCoordinationScopes;
337
+ };
338
+ const mapParameters = parameters => parameters
339
+ .map(parameter => AUXILIARY_COORDINATION_TYPES_MAP[parameter]).filter(Boolean).flat();
340
+ /**
341
+ * The useAuxiliaryCoordination hook returns both the
342
+ * values and setter functions for the auxiliary coordination objects
343
+ * in a particular coordination scope mapping.
344
+ * This hook is intended to be used within the ___Subscriber
345
+ * components to allow them to "hook into" only those auxiliary coordination
346
+ * objects and setter functions of relevance, for example "on load" callbacks.
347
+ * @param {string[]} parameters Array of coordination types.
348
+ * @param {object} coordinationScopes Mapping of coordination types
349
+ * to scope names.
350
+ * @returns {array} Returns a tuple [values, setters]
351
+ * where values is an object containing all coordination values,
352
+ * and setters is an object containing all coordination setter
353
+ * functions for the values in `values`, named with a "set"
354
+ * prefix.
355
+ */
356
+ export function useAuxiliaryCoordination(parameters, coordinationScopes) {
357
+ const setCoordinationValue = useAuxiliaryStore(state => state.setCoordinationValue);
358
+ const mappedCoordinationScopes = mapCoordinationScopes(coordinationScopes);
359
+ const mappedParameters = mapParameters(parameters);
360
+ const values = useAuxiliaryStore((state) => {
361
+ const { auxiliaryStore } = state;
362
+ return fromEntries(mappedParameters.map((parameter) => {
363
+ if (auxiliaryStore && auxiliaryStore[parameter]) {
364
+ const value = auxiliaryStore[parameter][mappedCoordinationScopes[parameter]];
365
+ return [parameter, value];
366
+ }
367
+ return [parameter, undefined];
368
+ }));
369
+ }, shallow);
370
+ const setters = useMemo(() => fromEntries(mappedParameters.map((parameter) => {
371
+ const setterName = `set${capitalize(parameter)}`;
372
+ const setterFunc = value => setCoordinationValue({
373
+ parameter,
374
+ scope: mappedCoordinationScopes[parameter],
375
+ value,
376
+ });
377
+ return [setterName, setterFunc];
378
+ // eslint-disable-next-line react-hooks/exhaustive-deps
379
+ })), [parameters, coordinationScopes]);
380
+ return [values, setters];
381
+ }
382
+ /**
383
+ * Obtain the loaders object from
384
+ * the global app state.
385
+ * @returns {object} The loaders object
386
+ * in the `useViewConfigStore` store.
387
+ */
388
+ export function useLoaders() {
389
+ return useViewConfigStore(state => state.loaders);
390
+ }
391
+ /**
392
+ * Find a specific loader instance for a particular dataset, data type, and view
393
+ * coordination values (mapping from coordination types to coordination values).
394
+ * Uses lodash/isMatch to perform matching against the file definition's
395
+ * coordination value mapping.
396
+ * @param {object} loaders The value returned by useLoaders.
397
+ * @param {string} dataset The dataset UID.
398
+ * @param {string} dataType The data type for the matching file.
399
+ * @param {object} viewCoordinationValues Current coordination values
400
+ * from the view. Match these against a subset of file definition coordination
401
+ * values.
402
+ * @returns The matching loader instance or `null`.
403
+ */
404
+ export function useMatchingLoader(loaders, dataset, dataType, viewCoordinationValues) {
405
+ return useMemo(() => {
406
+ if (!loaders[dataset]) {
407
+ return null;
408
+ }
409
+ const loaderInternMap = loaders[dataset].loaders[dataType];
410
+ if (!loaderInternMap) {
411
+ return null;
412
+ }
413
+ const loaderKeys = Array.from(loaderInternMap.keys());
414
+ const matchingKey = loaderKeys
415
+ .find(fileCoordinationValues => isMatch(fileCoordinationValues, viewCoordinationValues));
416
+ if (!matchingKey) {
417
+ return null;
418
+ }
419
+ return loaderInternMap.get(matchingKey);
420
+ }, [loaders, dataset, dataType, viewCoordinationValues]);
421
+ }
422
+ /**
423
+ * Find a specific loader instance for a particular dataset, data type, and view
424
+ * coordination values (mapping from coordination types to coordination values).
425
+ * Uses lodash/isMatch to perform matching against the file definition's
426
+ * coordination value mapping.
427
+ * @param {object} loaders The value returned by useLoaders.
428
+ * @param {string} dataset The dataset UID.
429
+ * @param {string} dataType The data type for the matching file.
430
+ * @param {object} viewCoordinationValues Current coordination values
431
+ * from the view. Match these against a subset of file definition coordination
432
+ * values.
433
+ * @returns The matching loader instance or `null`.
434
+ */
435
+ export function useMatchingLoaders(loaders, dataset, dataType, viewCoordinationValuesObj) {
436
+ return useMemo(() => {
437
+ if (!loaders[dataset]) {
438
+ return null;
439
+ }
440
+ const loaderInternMap = loaders[dataset].loaders[dataType];
441
+ if (!loaderInternMap) {
442
+ return null;
443
+ }
444
+ const loaderKeys = Array.from(loaderInternMap.keys());
445
+ function getLoader(viewCoordinationValues) {
446
+ const matchingKey = loaderKeys
447
+ .find(fileCoordinationValues => isMatch(fileCoordinationValues, viewCoordinationValues));
448
+ return loaderInternMap.get(matchingKey);
449
+ }
450
+ return fromEntries(Object.entries(viewCoordinationValuesObj).map(([key, viewCoordinationValues]) => ([
451
+ key,
452
+ getLoader(viewCoordinationValues),
453
+ ])));
454
+ }, [loaders, dataset, dataType, viewCoordinationValuesObj]);
455
+ }
456
+ /**
457
+ * Obtain the view config layout array from
458
+ * the global app state.
459
+ * @returns {object[]} The layout array
460
+ * in the `useViewConfigStore` store.
461
+ */
462
+ export function useLayout() {
463
+ return useViewConfigStore(state => state.viewConfig?.layout);
464
+ }
465
+ /**
466
+ * Obtain the component removal function from
467
+ * the global app state.
468
+ * @returns {function} The remove component function
469
+ * in the `useViewInfoStore` store.
470
+ */
471
+ export function useRemoveComponent() {
472
+ return useViewConfigStore(state => state.removeComponent);
473
+ }
474
+ /**
475
+ * Obtain the component prop setter function from
476
+ * the global app state.
477
+ * @returns {function} The set component props function
478
+ * in the `useViewInfoStore` store.
479
+ */
480
+ export function useChangeLayout() {
481
+ return useViewConfigStore(state => state.changeLayout);
482
+ }
483
+ /**
484
+ * Obtain the loaders setter function from
485
+ * the global app state.
486
+ * @returns {function} The loaders setter function
487
+ * in the `useViewConfigStore` store.
488
+ */
489
+ export function useSetLoaders() {
490
+ return useViewConfigStore(state => state.setLoaders);
491
+ }
492
+ /**
493
+ * Obtain the view config setter function from
494
+ * the global app state.
495
+ * @returns {function} The view config setter function
496
+ * in the `useViewConfigStore` store.
497
+ */
498
+ export function useSetViewConfig(viewConfigStoreApi) {
499
+ const setViewConfigRef = useRef(viewConfigStoreApi.getState().setViewConfig);
500
+ const setViewConfig = setViewConfigRef.current;
501
+ return setViewConfig;
502
+ }
503
+ /**
504
+ * Obtain the component hover value from
505
+ * the global app state.
506
+ * @returns {number} The hovered component ID
507
+ * in the `useHoverStore` store.
508
+ */
509
+ export function useComponentHover() {
510
+ return useHoverStore(state => state.componentHover);
511
+ }
512
+ /**
513
+ * Obtain the component hover setter function from
514
+ * the global app state.
515
+ * @returns {function} The component hover setter function
516
+ * in the `useHoverStore` store.
517
+ */
518
+ export function useSetComponentHover() {
519
+ return useHoverStore(state => state.setComponentHover);
520
+ }
521
+ /**
522
+ * Obtain the warning message from
523
+ * the global app state.
524
+ * @returns {string} The warning message
525
+ * in the `useWarnStore` store.
526
+ */
527
+ export function useWarning() {
528
+ return useWarnStore(state => state.warning);
529
+ }
530
+ /**
531
+ * Obtain the warning setter function from
532
+ * the global app state.
533
+ * @returns {function} The warning setter function
534
+ * in the `useWarnStore` store.
535
+ */
536
+ export function useSetWarning() {
537
+ return useWarnStore(state => state.setWarning);
538
+ }
539
+ /**
540
+ * Obtain the component view info value from
541
+ * the global app state.
542
+ * @returns {object} The view info object for the component
543
+ * in the `useViewInfoStore` store.
544
+ */
545
+ export function useComponentViewInfo(uuid) {
546
+ return useViewInfoStore(useCallback(state => state.viewInfo[uuid], [uuid]));
547
+ }
548
+ /**
549
+ * Obtain the component view info setter function from
550
+ * the global app state.
551
+ * @returns {function} The component view info setter function
552
+ * in the `useViewInfoStore` store.
553
+ */
554
+ export function useSetComponentViewInfo(uuid) {
555
+ const setViewInfoRef = useRef(useViewInfoStore.getState().setComponentViewInfo);
556
+ const setComponentViewInfo = useCallback(viewInfo => setViewInfoRef.current(uuid, viewInfo), [uuid]);
557
+ return setComponentViewInfo;
558
+ }
559
+ /**
560
+ * Obtain the grid resize count value
561
+ * from the global app state.
562
+ * @returns {number} The grid resize increment value.
563
+ */
564
+ export function useGridResize() {
565
+ return useGridSizeStore(state => state.resizeCount);
566
+ }
567
+ /**
568
+ * Obtain the grid resize count increment function
569
+ * from the global app state.
570
+ * @returns {function} The grid resize count increment
571
+ * function.
572
+ */
573
+ export function useEmitGridResize() {
574
+ return useGridSizeStore(state => state.incrementResizeCount);
575
+ }
@@ -0,0 +1,2 @@
1
+ export const useTitleStyles: (props?: any) => import("@material-ui/core/styles/withStyles").ClassNameMap<never>;
2
+ //# sourceMappingURL=title-styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"title-styles.d.ts","sourceRoot":"","sources":["../src/title-styles.js"],"names":[],"mappings":"AAEA,gHAsEI"}
@@ -0,0 +1,72 @@
1
+ import { makeStyles } from '@material-ui/core';
2
+ export const useTitleStyles = makeStyles(theme => ({
3
+ title: {
4
+ color: theme.palette.primaryForeground,
5
+ overflowX: 'hidden',
6
+ display: 'flex',
7
+ flexDirection: 'row',
8
+ flexShrink: '0',
9
+ },
10
+ titleLeft: {
11
+ flexShrink: '1',
12
+ textOverflow: 'ellipsis',
13
+ whiteSpace: 'nowrap',
14
+ },
15
+ titleInfo: {
16
+ width: '100%',
17
+ textOverflow: 'ellipsis',
18
+ whiteSpace: 'nowrap',
19
+ overflow: 'hidden',
20
+ fontSize: '80% !important',
21
+ opacity: '.8',
22
+ padding: '0 4px',
23
+ justifyContent: 'center',
24
+ lineHeight: '25px !important',
25
+ flexShrink: '1',
26
+ textAlign: 'right !important',
27
+ },
28
+ titleButtons: {
29
+ display: 'flex',
30
+ flexDirection: 'row',
31
+ flexGrow: '1',
32
+ flexShrink: '0',
33
+ justifyContent: 'right',
34
+ '& div': {
35
+ display: 'inline-block',
36
+ },
37
+ },
38
+ card: {
39
+ border: `1px solid ${theme.palette.cardBorder}`,
40
+ flex: '1 1 auto',
41
+ minHeight: '1px',
42
+ padding: '12px',
43
+ marginTop: '8px',
44
+ marginBottom: '8px',
45
+ position: 'relative',
46
+ display: 'flex',
47
+ flexDirection: 'column',
48
+ minWidth: '0',
49
+ wordWrap: 'break-word',
50
+ backgroundClip: 'border-box',
51
+ borderRadius: '4px',
52
+ },
53
+ noScrollCard: {
54
+ backgroundColor: theme.palette.secondaryBackground,
55
+ color: theme.palette.secondaryForeground,
56
+ },
57
+ scrollCard: {
58
+ backgroundColor: theme.palette.primaryBackground,
59
+ color: theme.palette.primaryForeground,
60
+ '& a': {
61
+ color: theme.palette.primaryForegroundActive,
62
+ },
63
+ overflowY: 'auto',
64
+ },
65
+ spatialCard: {
66
+ backgroundColor: theme.palette.black,
67
+ color: theme.palette.white,
68
+ '& a': {
69
+ color: theme.palette.white,
70
+ },
71
+ },
72
+ }));
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Get a list of all unique scope names for a
3
+ * particular coordination type, which exist in
4
+ * a particular view config.
5
+ * @param {object} config A view config object.
6
+ * @param {string} coordinationType A coordination type,
7
+ * for example 'spatialZoom' or 'dataset'.
8
+ * @returns {string[]} Array of existing coordination scope names.
9
+ */
10
+ export function getExistingScopesForCoordinationType(config: object, coordinationType: string): string[];
11
+ /**
12
+ * Initialize the view config:
13
+ * - Fill in missing coordination objects with default values.
14
+ * - Fill in missing component coordination scope mappings.
15
+ * based on the `initStrategy` specified in the view config.
16
+ * - Fill in missing view uid values.
17
+ * - Expand convenience file types.
18
+ * Should be "stable": if run on the same view config twice, the return value the second
19
+ * time should be identical to the return value the first time.
20
+ * @param {object} config The view config prop.
21
+ * @param {PluginJointFileType[]} jointFileTypes
22
+ * @param {PluginCoordinationType[]} coordinationTypes
23
+ * @param {PluginViewType[]} viewTypes
24
+ * @returns The initialized view config.
25
+ */
26
+ export function initialize(config: object, jointFileTypes: PluginJointFileType[], coordinationTypes: PluginCoordinationType[], viewTypes: PluginViewType[]): {
27
+ uid: any;
28
+ layout: any;
29
+ };
30
+ //# sourceMappingURL=view-config-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view-config-utils.d.ts","sourceRoot":"","sources":["../src/view-config-utils.js"],"names":[],"mappings":"AAQA;;;;;;;;GAQG;AACH,6DALW,MAAM,oBACN,MAAM,GAEJ,MAAM,EAAE,CAMpB;AAyND;;;;;;;;;;;;;;GAcG;AACH,mCANW,MAAM,kBACN,qBAAqB,qBACrB,wBAAwB,aACxB,gBAAgB;;;EAY1B"}