@vitessce/vit-s 2.0.3 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/dist/index.js +44072 -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 +50 -0
  12. package/dist-tsc/VitS.d.ts.map +1 -0
  13. package/dist-tsc/VitS.js +139 -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 +63 -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 +43 -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 +12 -0
  33. package/dist-tsc/data/LoaderResult.d.ts.map +1 -0
  34. package/dist-tsc/data/LoaderResult.js +12 -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 +65 -0
  42. package/dist-tsc/data-hook-utils.d.ts.map +1 -0
  43. package/dist-tsc/data-hook-utils.js +191 -0
  44. package/dist-tsc/data-hooks.d.ts +73 -0
  45. package/dist-tsc/data-hooks.d.ts.map +1 -0
  46. package/dist-tsc/data-hooks.js +254 -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 +76 -0
  66. package/dist-tsc/hooks.d.ts.map +1 -0
  67. package/dist-tsc/hooks.js +262 -0
  68. package/dist-tsc/index.d.ts +12 -0
  69. package/dist-tsc/index.d.ts.map +1 -0
  70. package/dist-tsc/index.js +11 -17
  71. package/dist-tsc/mui-utils.d.ts +2 -0
  72. package/dist-tsc/mui-utils.d.ts.map +1 -0
  73. package/dist-tsc/mui-utils.js +44 -0
  74. package/dist-tsc/plugins.test.fixtures.d.ts +61 -0
  75. package/dist-tsc/plugins.test.fixtures.d.ts.map +1 -0
  76. package/dist-tsc/plugins.test.fixtures.js +76 -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-tsc/shared-mui/components.js +29 -0
  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-tsc/shared-mui/container.js +211 -0
  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-tsc/shared-mui/styles.js +109 -0
  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-tsc/shared-plot-options/CellColorEncodingOption.js +17 -0
  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-tsc/shared-plot-options/OptionSelect.js +12 -0
  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-tsc/shared-plot-options/OptionsContainer.js +9 -0
  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-tsc/shared-plot-options/styles.js +48 -0
  101. package/dist-tsc/state/hooks.d.ts +242 -0
  102. package/dist-tsc/state/hooks.d.ts.map +1 -0
  103. package/dist-tsc/state/hooks.js +615 -0
  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 +31 -0
  108. package/dist-tsc/view-config-utils.d.ts.map +1 -0
  109. package/dist-tsc/view-config-utils.js +240 -0
  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-tsc/view-config-utils.test.fixtures.js +883 -0
  115. package/dist-tsc/view-config-utils.test.js +210 -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-tsc/vitessce-grid-layout/VitessceGridLayout.js +114 -0
  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-tsc/vitessce-grid-layout/VitessceGridLayout.test.js +48 -0
  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-tsc/vitessce-grid-layout/layout-utils.js +61 -0
  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-tsc/vitessce-grid-layout/layout-utils.test.js +149 -0
  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-tsc/vitessce-grid-utils.js +141 -0
  134. package/package.json +25 -11
  135. package/src/CallbackPublisher.js +7 -11
  136. package/src/LoadingIndicator.js +1 -2
  137. package/src/TitleInfo.js +12 -85
  138. package/src/VitS.js +143 -85
  139. package/src/VitessceGrid.js +35 -21
  140. package/src/VitessceGrid.test.jsx +23 -8
  141. package/src/Warning.js +4 -4
  142. package/src/data/AbstractLoader.js +2 -25
  143. package/src/data/AbstractTwoStepLoader.js +1 -1
  144. package/src/data/LoaderResult.js +5 -0
  145. package/src/data/index.js +3 -3
  146. package/src/data/loader-registry.js +22 -13
  147. package/src/data-hook-utils.js +119 -86
  148. package/src/data-hooks.js +150 -131
  149. package/src/errors/DataSourceFetchError.js +2 -2
  150. package/src/errors/DatasetNotFoundError.js +1 -1
  151. package/src/errors/LoaderNotFoundError.js +1 -1
  152. package/src/errors/LoaderValidationError.js +1 -1
  153. package/src/errors/index.js +5 -6
  154. package/src/hooks.js +81 -26
  155. package/src/index.js +23 -46
  156. package/src/mui-utils.js +52 -0
  157. package/src/shared-mui/components.js +10 -8
  158. package/src/shared-mui/container.js +1 -1
  159. package/src/shared-mui/styles.js +5 -2
  160. package/src/shared-plot-options/CellColorEncodingOption.js +3 -4
  161. package/src/shared-plot-options/OptionSelect.js +3 -3
  162. package/src/shared-plot-options/OptionsContainer.js +2 -5
  163. package/src/shared-plot-options/index.js +4 -4
  164. package/src/shared-plot-options/styles.js +2 -2
  165. package/src/state/hooks.js +75 -23
  166. package/src/title-styles.js +73 -0
  167. package/src/view-config-utils.js +54 -98
  168. package/src/view-config-utils.test.jsx +223 -0
  169. package/src/vitessce-grid-layout/VitessceGridLayout.js +51 -30
  170. package/src/vitessce-grid-layout/VitessceGridLayout.test.jsx +17 -9
  171. package/src/vitessce-grid-layout/index.js +1 -1
  172. package/src/vitessce-grid-layout/layout-utils.js +1 -1
  173. package/src/vitessce-grid-layout/layout-utils.test.js +2 -1
  174. package/src/vitessce-grid-utils.js +27 -15
  175. package/dist/index.mjs +0 -84801
  176. package/src/component-registry.js +0 -21
  177. package/src/errors/OptionsValidationError.js +0 -25
  178. package/src/file-options-schemas-legacy.js +0 -139
  179. package/src/file-options-schemas-legacy.test.js +0 -138
  180. package/src/file-options-schemas.js +0 -327
  181. package/src/file-options-schemas.test.js +0 -26
  182. package/src/joint-file-types-legacy.js +0 -298
  183. package/src/joint-file-types-legacy.test.js +0 -412
  184. package/src/joint-file-types.js +0 -171
  185. package/src/joint-file-types.test.js +0 -144
  186. package/src/json-schemas.js +0 -9
  187. package/src/plugins.js +0 -186
  188. package/src/plugins.test.js +0 -42
  189. package/src/schemas/config-0.1.0.schema.json +0 -85
  190. package/src/schemas/config-1.0.0.schema.json +0 -733
  191. package/src/schemas/config-1.0.1.schema.json +0 -909
  192. package/src/schemas/config-1.0.10.schema.json +0 -969
  193. package/src/schemas/config-1.0.11.schema.json +0 -990
  194. package/src/schemas/config-1.0.12.schema.json +0 -997
  195. package/src/schemas/config-1.0.13.schema.json +0 -1013
  196. package/src/schemas/config-1.0.14.schema.json +0 -1048
  197. package/src/schemas/config-1.0.15.schema.json +0 -1048
  198. package/src/schemas/config-1.0.16.schema.json +0 -1069
  199. package/src/schemas/config-1.0.16.schema.test.js +0 -32
  200. package/src/schemas/config-1.0.2.schema.json +0 -911
  201. package/src/schemas/config-1.0.3.schema.json +0 -911
  202. package/src/schemas/config-1.0.4.schema.json +0 -949
  203. package/src/schemas/config-1.0.5.schema.json +0 -949
  204. package/src/schemas/config-1.0.6.schema.json +0 -950
  205. package/src/schemas/config-1.0.7.schema.json +0 -950
  206. package/src/schemas/config-1.0.8.schema.json +0 -966
  207. package/src/schemas/config-1.0.9.schema.json +0 -965
  208. package/src/schemas/obsSets.schema.js +0 -195
  209. package/src/schemas/obsSetsTabular.schema.js +0 -39
  210. package/src/schemas/raster.schema.js +0 -121
  211. package/src/schemas/schema-schema.sh +0 -34
  212. package/src/schemas/schema.test-old.js +0 -49
  213. package/src/view-config-upgraders.js +0 -628
  214. package/src/view-config-utils.test.js +0 -95
  215. package/src/view-config-versions.js +0 -68
@@ -0,0 +1,31 @@
1
+ export function logConfig(config: any, name: any): void;
2
+ /**
3
+ * Get a list of all unique scope names for a
4
+ * particular coordination type, which exist in
5
+ * a particular view config.
6
+ * @param {object} config A view config object.
7
+ * @param {string} coordinationType A coordination type,
8
+ * for example 'spatialZoom' or 'dataset'.
9
+ * @returns {string[]} Array of existing coordination scope names.
10
+ */
11
+ export function getExistingScopesForCoordinationType(config: object, coordinationType: string): string[];
12
+ /**
13
+ * Initialize the view config:
14
+ * - Fill in missing coordination objects with default values.
15
+ * - Fill in missing component coordination scope mappings.
16
+ * based on the `initStrategy` specified in the view config.
17
+ * - Fill in missing view uid values.
18
+ * - Expand convenience file types.
19
+ * Should be "stable": if run on the same view config twice, the return value the second
20
+ * time should be identical to the return value the first time.
21
+ * @param {object} config The view config prop.
22
+ * @param {PluginJointFileType[]} jointFileTypes
23
+ * @param {PluginCoordinationType[]} coordinationTypes
24
+ * @param {PluginViewType[]} viewTypes
25
+ * @returns The initialized view config.
26
+ */
27
+ export function initialize(config: object, jointFileTypes: PluginJointFileType[], coordinationTypes: PluginCoordinationType[], viewTypes: PluginViewType[]): {
28
+ uid: any;
29
+ layout: any;
30
+ };
31
+ //# 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":"AASA,wDAKC;AAED;;;;;;;;GAQG;AACH,6DALW,MAAM,oBACN,MAAM,GAEJ,MAAM,EAAE,CAMpB;AAyND;;;;;;;;;;;;;;GAcG;AACH,mCANW,MAAM,kBACN,qBAAqB,qBACrB,wBAAwB,aACxB,gBAAgB;;;EAY1B"}
@@ -0,0 +1,240 @@
1
+ /* eslint-disable no-plusplus */
2
+ /* eslint-disable camelcase */
3
+ import { cloneDeep } from 'lodash-es';
4
+ import { fromEntries, getNextScope } from '@vitessce/utils';
5
+ import { AUTO_INDEPENDENT_COORDINATION_TYPES, META_VERSION, } from '@vitessce/constants-internal';
6
+ export function logConfig(config, name) {
7
+ console.groupCollapsed(`🚄 VitS (${META_VERSION.version}) ${name}`);
8
+ console.info(`data:,${JSON.stringify(config)}`);
9
+ console.info(JSON.stringify(config, null, 2));
10
+ console.groupEnd();
11
+ }
12
+ /**
13
+ * Get a list of all unique scope names for a
14
+ * particular coordination type, which exist in
15
+ * a particular view config.
16
+ * @param {object} config A view config object.
17
+ * @param {string} coordinationType A coordination type,
18
+ * for example 'spatialZoom' or 'dataset'.
19
+ * @returns {string[]} Array of existing coordination scope names.
20
+ */
21
+ export function getExistingScopesForCoordinationType(config, coordinationType) {
22
+ const spaceScopes = Object.keys(config?.coordinationSpace?.[coordinationType] || {});
23
+ const componentScopes = config.layout.map(c => c.coordinationScopes?.[coordinationType]);
24
+ return Array.from(new Set([...spaceScopes, ...componentScopes]));
25
+ }
26
+ /**
27
+ * Give each component the same scope name for this coordination type.
28
+ * @param {object} config A view config object.
29
+ * @param {string} coordinationType A coordination type,
30
+ * for example 'spatialZoom' or 'dataset'.
31
+ * @param {*} scopeValue The initial value for the coordination scope,
32
+ * to set in the coordination space.
33
+ * @returns {object} The new view config.
34
+ */
35
+ function coordinateComponentsTogether(config, coordinationType, scopeValue, viewTypes) {
36
+ const componentCoordinationTypes = fromEntries(viewTypes.map(vt => ([vt.name, vt.coordinationTypes])));
37
+ const scopeName = getNextScope(getExistingScopesForCoordinationType(config, coordinationType));
38
+ const newConfig = {
39
+ ...config,
40
+ coordinationSpace: {
41
+ ...config.coordinationSpace,
42
+ [coordinationType]: {
43
+ ...config?.coordinationSpace?.[coordinationType],
44
+ // Add the new scope name and value to the coordination space.
45
+ [scopeName]: scopeValue,
46
+ },
47
+ },
48
+ layout: config.layout.map(component => ({
49
+ ...component,
50
+ coordinationScopes: {
51
+ ...component.coordinationScopes,
52
+ // Only set the coordination scope if this component uses this coordination type,
53
+ // and the component is missing a coordination scope for this coordination type.
54
+ ...((componentCoordinationTypes[component.component].includes(coordinationType)
55
+ && !component.coordinationScopes?.[coordinationType]) ? {
56
+ // Only set the new scope name if the scope name
57
+ // for this component and coordination type is currently undefined.
58
+ [coordinationType]: scopeName,
59
+ } : {}),
60
+ },
61
+ })),
62
+ };
63
+ return newConfig;
64
+ }
65
+ /**
66
+ * Give each component a different scope name for this coordination type.
67
+ * @param {object} config A view config object.
68
+ * @param {string} coordinationType A coordination type,
69
+ * for example 'spatialZoom' or 'dataset'.
70
+ * @param {*} scopeValue The initial value for the coordination scope,
71
+ * to set in the coordination space.
72
+ * @returns {object} The new view config.
73
+ */
74
+ function coordinateComponentsIndependent(config, coordinationType, scopeValue, viewTypes) {
75
+ const componentCoordinationTypes = fromEntries(viewTypes.map(vt => ([vt.name, vt.coordinationTypes])));
76
+ const newConfig = {
77
+ ...config,
78
+ layout: [...config.layout],
79
+ };
80
+ const newScopes = {};
81
+ newConfig.layout.forEach((component, i) => {
82
+ // Only set the coordination scope if this component uses this coordination type,
83
+ // and the component is missing a coordination scope for this coordination type.
84
+ if (componentCoordinationTypes[component.component].includes(coordinationType)
85
+ && !component.coordinationScopes?.[coordinationType]) {
86
+ const scopeName = getNextScope([
87
+ ...getExistingScopesForCoordinationType(config, coordinationType),
88
+ ...Object.keys(newScopes),
89
+ ]);
90
+ newScopes[scopeName] = scopeValue;
91
+ newConfig.layout[i] = {
92
+ ...component,
93
+ coordinationScopes: {
94
+ ...component.coordinationScopes,
95
+ [coordinationType]: scopeName,
96
+ },
97
+ };
98
+ }
99
+ });
100
+ newConfig.coordinationSpace = {
101
+ ...newConfig.coordinationSpace,
102
+ [coordinationType]: {
103
+ ...newConfig.coordinationSpace[coordinationType],
104
+ // Add the new scope name and value to the coordination space.
105
+ ...newScopes,
106
+ },
107
+ };
108
+ return newConfig;
109
+ }
110
+ /**
111
+ * Perform initialization using initStrategy: "auto".
112
+ * @param {object} config The view config.
113
+ * @param {PluginCoordinationType[]} coordinationTypeObjs
114
+ * @param {PluginViewType[]} viewTypeObjs
115
+ * @returns {object} The config.
116
+ */
117
+ function initializeAuto(config, coordinationTypeObjs, viewTypeObjs) {
118
+ let newConfig = config;
119
+ const { layout, datasets } = newConfig;
120
+ const componentCoordinationTypes = fromEntries(viewTypeObjs.map(vt => ([vt.name, vt.coordinationTypes])));
121
+ const defaultCoordinationValues = fromEntries(coordinationTypeObjs.map(ct => ([ct.name, ct.defaultValue])));
122
+ const coordinationTypes = coordinationTypeObjs.map(ct => ct.name);
123
+ // For each coordination type, check whether it requires initialization.
124
+ coordinationTypes.forEach((coordinationType) => {
125
+ // A coordination type requires coordination if at least one component is missing
126
+ // a (coordination type, coordination scope) tuple.
127
+ // Components may only use a subset of all coordination types.
128
+ const requiresCoordination = !layout
129
+ .every(c => ((!componentCoordinationTypes[c.component].includes(coordinationType))
130
+ || c.coordinationScopes?.[coordinationType]));
131
+ if (requiresCoordination) {
132
+ // Note that the default value may be undefined.
133
+ let defaultValue = defaultCoordinationValues[coordinationType];
134
+ // Check whether this is the special 'dataset' coordination type.
135
+ if (coordinationType === 'dataset' && datasets.length >= 1) {
136
+ // Use the first dataset ID as the default
137
+ // if there is at least one dataset.
138
+ defaultValue = datasets[0].uid;
139
+ }
140
+ // Use the list of "independent" coordination types
141
+ // to determine whether a particular coordination type
142
+ // should be initialized to
143
+ // a unique scope for every component ("independent")
144
+ // vs. the same scope for every component ("together").
145
+ if (AUTO_INDEPENDENT_COORDINATION_TYPES.includes(coordinationType)) {
146
+ newConfig = coordinateComponentsIndependent(newConfig, coordinationType, defaultValue, viewTypeObjs);
147
+ }
148
+ else {
149
+ newConfig = coordinateComponentsTogether(newConfig, coordinationType, defaultValue, viewTypeObjs);
150
+ }
151
+ }
152
+ });
153
+ return newConfig;
154
+ }
155
+ /**
156
+ * Assign unique ids for view definitions where
157
+ * they are missing a value for the uid property
158
+ * in layout[].uid.
159
+ * @param {object} config The view config
160
+ * @returns The updated view config.
161
+ */
162
+ function assignViewUids(config) {
163
+ const { uid, layout } = config;
164
+ const usedIds = layout.map(view => view.uid);
165
+ layout.forEach((view, i) => {
166
+ // Assign uids for views where they are not present.
167
+ if (!view.uid) {
168
+ const nextUid = getNextScope(usedIds);
169
+ layout[i].uid = nextUid;
170
+ usedIds.push(nextUid);
171
+ }
172
+ });
173
+ const newUid = uid || getNextScope([]);
174
+ return {
175
+ ...config,
176
+ uid: newUid,
177
+ layout,
178
+ };
179
+ }
180
+ /**
181
+ * Expand convenience file definitions. Each convenience file
182
+ * definition expansion function takes in one file definition and
183
+ * returns an array of file definitions. Not performed recursively.
184
+ * @param {object} config The view config containing collapsed
185
+ * convenience file types.
186
+ * @returns The view config containing expanded minimal file types.
187
+ */
188
+ function expandConvenienceFileDefs(config, jointFileTypes) {
189
+ const convenienceFileTypes = fromEntries(jointFileTypes.map(ft => ([ft.name, ft.expandFunction])));
190
+ const { datasets: currDatasets } = config;
191
+ const datasets = cloneDeep(currDatasets);
192
+ currDatasets.forEach((dataset, i) => {
193
+ const { files = [] } = dataset;
194
+ let newFiles = [];
195
+ files.forEach((fileDef) => {
196
+ const { fileType } = fileDef;
197
+ const expansionFunc = convenienceFileTypes[fileType];
198
+ if (expansionFunc && typeof expansionFunc === 'function') {
199
+ // This was a convenience file type, so expand it.
200
+ const expandedFileDefs = expansionFunc(fileDef);
201
+ newFiles = newFiles.concat(expandedFileDefs);
202
+ }
203
+ else {
204
+ // This was not a convenience file type,
205
+ // so keep it in the files array as-is.
206
+ newFiles.push(fileDef);
207
+ }
208
+ });
209
+ datasets[i].files = newFiles;
210
+ });
211
+ return {
212
+ ...config,
213
+ datasets,
214
+ };
215
+ }
216
+ /**
217
+ * Initialize the view config:
218
+ * - Fill in missing coordination objects with default values.
219
+ * - Fill in missing component coordination scope mappings.
220
+ * based on the `initStrategy` specified in the view config.
221
+ * - Fill in missing view uid values.
222
+ * - Expand convenience file types.
223
+ * Should be "stable": if run on the same view config twice, the return value the second
224
+ * time should be identical to the return value the first time.
225
+ * @param {object} config The view config prop.
226
+ * @param {PluginJointFileType[]} jointFileTypes
227
+ * @param {PluginCoordinationType[]} coordinationTypes
228
+ * @param {PluginViewType[]} viewTypes
229
+ * @returns The initialized view config.
230
+ */
231
+ export function initialize(config, jointFileTypes, coordinationTypes, viewTypes) {
232
+ let newConfig = cloneDeep(config);
233
+ if (newConfig.initStrategy === 'auto') {
234
+ // TODO: pass coordination types with defaults
235
+ // TODO: pass view types with per-view coordination type lists
236
+ newConfig = initializeAuto(config, coordinationTypes, viewTypes);
237
+ }
238
+ newConfig = expandConvenienceFileDefs(newConfig, jointFileTypes);
239
+ return assignViewUids(newConfig);
240
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=view-config-utils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view-config-utils.test.d.ts","sourceRoot":"","sources":["../src/view-config-utils.test.jsx"],"names":[],"mappings":""}