@jbrowse/core 2.0.1 → 2.1.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 (179) hide show
  1. package/BaseFeatureWidget/BaseFeatureDetail.d.ts +6 -0
  2. package/BaseFeatureWidget/BaseFeatureDetail.js +313 -592
  3. package/BaseFeatureWidget/SequenceFeatureDetails.js +213 -479
  4. package/BaseFeatureWidget/index.js +88 -126
  5. package/BaseFeatureWidget/types.js +1 -4
  6. package/BaseFeatureWidget/util.js +40 -75
  7. package/CorePlugin.js +55 -94
  8. package/Plugin.js +9 -34
  9. package/PluginLoader.js +153 -422
  10. package/PluginManager.d.ts +17 -14
  11. package/PluginManager.js +377 -666
  12. package/ReExports/Attributes.js +3 -10
  13. package/ReExports/BaseCard.js +3 -10
  14. package/ReExports/DataGrid.js +5 -12
  15. package/ReExports/FeatureDetails.js +3 -10
  16. package/ReExports/index.js +6 -12
  17. package/ReExports/list.d.ts +5 -0
  18. package/ReExports/list.js +271 -7
  19. package/ReExports/material-ui-colors.js +15 -16
  20. package/ReExports/modules.d.ts +0 -1
  21. package/ReExports/modules.js +453 -798
  22. package/TextSearch/BaseResults.js +51 -123
  23. package/TextSearch/TextSearchManager.js +66 -144
  24. package/assemblyManager/assembly.js +280 -555
  25. package/assemblyManager/assemblyConfigSchema.js +47 -64
  26. package/assemblyManager/assemblyManager.js +126 -272
  27. package/assemblyManager/index.js +9 -22
  28. package/configuration/configurationSchema.js +167 -203
  29. package/configuration/configurationSlot.js +248 -326
  30. package/configuration/index.js +19 -35
  31. package/configuration/util.js +131 -173
  32. package/data_adapters/BaseAdapter.d.ts +2 -2
  33. package/data_adapters/BaseAdapter.js +132 -521
  34. package/data_adapters/CytobandAdapter.js +40 -126
  35. package/data_adapters/dataAdapterCache.js +77 -158
  36. package/package.json +4 -5
  37. package/pluggableElementTypes/AdapterType.js +24 -79
  38. package/pluggableElementTypes/AddTrackWorkflowType.d.ts +17 -0
  39. package/pluggableElementTypes/AddTrackWorkflowType.js +20 -0
  40. package/pluggableElementTypes/ConnectionType.js +22 -65
  41. package/pluggableElementTypes/DisplayType.js +35 -82
  42. package/pluggableElementTypes/InternetAccountType.js +23 -64
  43. package/pluggableElementTypes/PluggableElementBase.js +8 -20
  44. package/pluggableElementTypes/RpcMethodType.js +85 -427
  45. package/pluggableElementTypes/TextSearchAdapterType.js +16 -55
  46. package/pluggableElementTypes/TrackType.js +26 -70
  47. package/pluggableElementTypes/ViewType.js +21 -63
  48. package/pluggableElementTypes/WidgetType.js +21 -64
  49. package/pluggableElementTypes/index.d.ts +4 -3
  50. package/pluggableElementTypes/index.js +42 -125
  51. package/pluggableElementTypes/models/BaseConnectionModelFactory.js +28 -43
  52. package/pluggableElementTypes/models/BaseDisplayModel.js +58 -95
  53. package/pluggableElementTypes/models/BaseTrackModel.js +139 -199
  54. package/pluggableElementTypes/models/BaseViewModel.js +24 -40
  55. package/pluggableElementTypes/models/InternetAccountModel.js +116 -263
  56. package/pluggableElementTypes/models/baseConnectionConfig.js +14 -25
  57. package/pluggableElementTypes/models/baseInternetAccountConfig.js +29 -38
  58. package/pluggableElementTypes/models/baseTrackConfig.js +106 -133
  59. package/pluggableElementTypes/models/index.js +21 -70
  60. package/pluggableElementTypes/renderers/BoxRendererType.js +132 -291
  61. package/pluggableElementTypes/renderers/CircularChordRendererType.js +8 -38
  62. package/pluggableElementTypes/renderers/ComparativeServerSideRendererType.js +60 -192
  63. package/pluggableElementTypes/renderers/FeatureRendererType.d.ts +0 -2
  64. package/pluggableElementTypes/renderers/FeatureRendererType.js +89 -264
  65. package/pluggableElementTypes/renderers/RendererType.js +31 -105
  66. package/pluggableElementTypes/renderers/ServerSideRenderedContent.js +61 -72
  67. package/pluggableElementTypes/renderers/ServerSideRendererType.js +112 -265
  68. package/pluggableElementTypes/renderers/index.js +19 -62
  69. package/pluggableElementTypes/renderers/util/serializableFilterChain.js +27 -65
  70. package/rpc/BaseRpcDriver.js +169 -405
  71. package/rpc/MainThreadRpcDriver.js +27 -150
  72. package/rpc/RpcManager.js +58 -159
  73. package/rpc/WebWorkerRpcDriver.js +54 -171
  74. package/rpc/configSchema.js +25 -49
  75. package/rpc/coreRpcMethods.js +221 -959
  76. package/rpc/remoteAbortSignals.js +46 -70
  77. package/tsconfig.build.tsbuildinfo +1 -1
  78. package/ui/AboutDialog.js +106 -162
  79. package/ui/App.js +157 -242
  80. package/ui/AssemblySelector.js +59 -120
  81. package/ui/CascadingMenu.js +101 -196
  82. package/ui/ColorPicker.d.ts +16 -0
  83. package/ui/ColorPicker.js +97 -0
  84. package/ui/Drawer.js +28 -61
  85. package/ui/DrawerWidget.js +108 -202
  86. package/ui/DropDownMenu.js +60 -91
  87. package/ui/EditableTypography.js +87 -149
  88. package/ui/ErrorMessage.js +41 -56
  89. package/ui/FactoryResetDialog.js +24 -57
  90. package/ui/FatalErrorDialog.js +59 -91
  91. package/ui/FileSelector/FileSelector.js +123 -189
  92. package/ui/FileSelector/LocalFileChooser.js +44 -75
  93. package/ui/FileSelector/UrlChooser.js +17 -38
  94. package/ui/FileSelector/index.js +6 -12
  95. package/ui/Icons.js +45 -69
  96. package/ui/Logo.js +57 -110
  97. package/ui/Menu.js +232 -354
  98. package/ui/PrerenderedCanvas.js +63 -87
  99. package/ui/ResizeHandle.js +87 -116
  100. package/ui/ReturnToImportFormDialog.js +32 -63
  101. package/ui/SanitizedHTML.js +64 -47
  102. package/ui/Snackbar.js +74 -101
  103. package/ui/SnackbarModel.js +37 -51
  104. package/ui/Tooltip.js +49 -76
  105. package/ui/ViewContainer.js +113 -196
  106. package/ui/colors.d.ts +10 -0
  107. package/ui/colors.js +78 -0
  108. package/ui/index.js +51 -181
  109. package/ui/react-colorful.d.ts +17 -0
  110. package/ui/react-colorful.js +455 -0
  111. package/ui/theme.js +199 -247
  112. package/util/Base1DUtils.js +163 -202
  113. package/util/Base1DViewModel.js +121 -168
  114. package/util/QuickLRU.js +84 -332
  115. package/util/TimeTraveller.d.ts +19 -0
  116. package/util/TimeTraveller.js +86 -0
  117. package/util/aborting.js +49 -127
  118. package/util/analytics.js +91 -154
  119. package/util/blockTypes.js +106 -240
  120. package/util/calculateDynamicBlocks.js +98 -128
  121. package/util/calculateStaticBlocks.js +105 -125
  122. package/util/color/cssColorsLevel4.js +156 -160
  123. package/util/color/index.js +33 -55
  124. package/util/compositeMap.js +49 -333
  125. package/util/formatFastaStrings.js +9 -14
  126. package/util/idMaker.js +18 -31
  127. package/util/index.d.ts +7 -20
  128. package/util/index.js +742 -1188
  129. package/util/io/RemoteFileWithRangeCache.js +88 -257
  130. package/util/io/index.js +95 -169
  131. package/util/jexl.js +60 -115
  132. package/util/jexlStrings.js +24 -29
  133. package/util/layouts/BaseLayout.js +1 -4
  134. package/util/layouts/GranularRectLayout.js +388 -555
  135. package/util/layouts/MultiLayout.js +41 -109
  136. package/util/layouts/PrecomputedLayout.js +56 -112
  137. package/util/layouts/PrecomputedMultiLayout.js +22 -59
  138. package/util/layouts/SceneGraph.js +127 -197
  139. package/util/layouts/index.js +29 -66
  140. package/util/mst-reflection.js +55 -71
  141. package/util/offscreenCanvasPonyfill.js +66 -134
  142. package/util/offscreenCanvasUtils.d.ts +2 -7
  143. package/util/offscreenCanvasUtils.js +49 -146
  144. package/util/range.js +29 -40
  145. package/util/rxjs.js +20 -27
  146. package/util/simpleFeature.js +88 -152
  147. package/util/stats.js +91 -151
  148. package/util/tracks.js +130 -173
  149. package/util/types/index.js +110 -179
  150. package/util/types/mst.js +91 -146
  151. package/util/types/util.js +1 -4
  152. package/util/when.js +54 -101
  153. package/BaseFeatureWidget/SequenceFeatureDetails.test.js +0 -122
  154. package/BaseFeatureWidget/index.test.js +0 -69
  155. package/TextSearch/BaseResults.test.js +0 -42
  156. package/configuration/configurationSchema.test.js +0 -266
  157. package/configuration/configurationSlot.test.js +0 -69
  158. package/configuration/util.test.js +0 -39
  159. package/data_adapters/BaseAdapter.test.js +0 -200
  160. package/declare.d.js +0 -1
  161. package/pluggableElementTypes/RpcMethodType.test.js +0 -118
  162. package/pluggableElementTypes/renderers/declare.d.js +0 -1
  163. package/pluggableElementTypes/renderers/util/serializableFilterChain.test.js +0 -20
  164. package/rpc/BaseRpcDriver.test.js +0 -540
  165. package/rpc/declaration.d.js +0 -1
  166. package/ui/FatalErrorDialog.test.js +0 -82
  167. package/ui/SanitizedHTML.test.js +0 -36
  168. package/ui/theme.test.js +0 -92
  169. package/util/Base1DViewModel.test.js +0 -130
  170. package/util/calculateDynamicBlocks.test.js +0 -74
  171. package/util/calculateStaticBlocks.test.js +0 -297
  172. package/util/declare.d.js +0 -1
  173. package/util/formatFastaStrings.test.js +0 -40
  174. package/util/index.test.js +0 -213
  175. package/util/jexlStrings.test.js +0 -48
  176. package/util/layouts/GranularRectLayout.test.js +0 -99
  177. package/util/range.test.js +0 -64
  178. package/util/simpleFeature.test.js +0 -34
  179. package/util/stats.test.js +0 -172
@@ -1,222 +1,186 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.ConfigurationReference = ConfigurationReference;
9
- exports.ConfigurationSchema = ConfigurationSchema;
10
-
11
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
-
13
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
-
15
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
16
-
17
- var _mobxStateTree = require("mobx-state-tree");
18
-
19
- var _mst = require("../util/types/mst");
20
-
21
- var _configurationSlot = _interopRequireDefault(require("./configurationSlot"));
22
-
23
- var _util = require("./util");
24
-
25
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
26
-
27
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
28
-
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ConfigurationReference = exports.ConfigurationSchema = void 0;
7
+ const mobx_state_tree_1 = require("mobx-state-tree");
8
+ const mst_1 = require("../util/types/mst");
9
+ const configurationSlot_1 = __importDefault(require("./configurationSlot"));
10
+ const util_1 = require("./util");
29
11
  function isEmptyObject(thing) {
30
- return (0, _typeof2.default)(thing) === 'object' && !Array.isArray(thing) && thing !== null && Object.keys(thing).length === 0;
12
+ return (typeof thing === 'object' &&
13
+ !Array.isArray(thing) &&
14
+ thing !== null &&
15
+ Object.keys(thing).length === 0);
31
16
  }
32
-
33
17
  function isEmptyArray(thing) {
34
- return Array.isArray(thing) && thing.length === 0;
18
+ return Array.isArray(thing) && thing.length === 0;
35
19
  }
36
-
37
- function preprocessConfigurationSchemaArguments(modelName, inputSchemaDefinition) {
38
- var inputOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
39
-
40
- if (typeof modelName !== 'string') {
41
- throw new Error('first arg must be string name of the model that this config schema goes with');
42
- } // if we have a base configuration schema that we are
43
- // extending, grab the slot definitions from that
44
-
45
-
46
- var schemaDefinition = inputSchemaDefinition;
47
- var options = inputOptions;
48
-
49
- if (inputOptions.baseConfiguration && inputOptions.baseConfiguration.jbrowseSchemaDefinition) {
50
- schemaDefinition = _objectSpread(_objectSpread({}, inputOptions.baseConfiguration.jbrowseSchemaDefinition), schemaDefinition);
51
- options = _objectSpread(_objectSpread({}, inputOptions.baseConfiguration.jbrowseSchemaOptions || {}), inputOptions);
52
- delete options.baseConfiguration;
53
- }
54
-
55
- return {
56
- schemaDefinition: schemaDefinition,
57
- options: options
58
- };
20
+ function preprocessConfigurationSchemaArguments(modelName, inputSchemaDefinition, inputOptions = {}) {
21
+ if (typeof modelName !== 'string') {
22
+ throw new Error('first arg must be string name of the model that this config schema goes with');
23
+ }
24
+ // if we have a base configuration schema that we are
25
+ // extending, grab the slot definitions from that
26
+ let schemaDefinition = inputSchemaDefinition;
27
+ let options = inputOptions;
28
+ if (inputOptions.baseConfiguration &&
29
+ inputOptions.baseConfiguration.jbrowseSchemaDefinition) {
30
+ schemaDefinition = {
31
+ ...inputOptions.baseConfiguration.jbrowseSchemaDefinition,
32
+ ...schemaDefinition,
33
+ };
34
+ options = {
35
+ ...(inputOptions.baseConfiguration.jbrowseSchemaOptions || {}),
36
+ ...inputOptions,
37
+ };
38
+ delete options.baseConfiguration;
39
+ }
40
+ return { schemaDefinition, options };
59
41
  }
60
-
61
42
  function makeConfigurationSchemaModel(modelName, schemaDefinition, options) {
62
- // now assemble the MST model of the configuration schema
63
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
- var modelDefinition = {};
65
- var identifier;
66
-
67
- if (options.explicitlyTyped) {
68
- modelDefinition.type = _mobxStateTree.types.optional(_mobxStateTree.types.literal(modelName), modelName);
69
- }
70
-
71
- if (options.explicitIdentifier && options.implicitIdentifier) {
72
- throw new Error("Cannot have both explicit and implicit identifiers in ".concat(modelName));
73
- }
74
-
75
- if (options.explicitIdentifier) {
76
- if (typeof options.explicitIdentifier === 'string') {
77
- modelDefinition[options.explicitIdentifier] = _mobxStateTree.types.identifier;
78
- identifier = options.explicitIdentifier;
79
- } else {
80
- modelDefinition.id = _mobxStateTree.types.identifier;
81
- identifier = 'id';
82
- }
83
- } else if (options.implicitIdentifier) {
84
- if (typeof options.implicitIdentifier === 'string') {
85
- modelDefinition[options.implicitIdentifier] = _mst.ElementId;
86
- identifier = options.implicitIdentifier;
87
- } else {
88
- modelDefinition.id = _mst.ElementId;
89
- identifier = 'id';
43
+ // now assemble the MST model of the configuration schema
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ const modelDefinition = {};
46
+ let identifier;
47
+ if (options.explicitlyTyped) {
48
+ modelDefinition.type = mobx_state_tree_1.types.optional(mobx_state_tree_1.types.literal(modelName), modelName);
90
49
  }
91
- } // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
-
93
-
94
- var volatileConstants = {
95
- isJBrowseConfigurationSchema: true,
96
- jbrowseSchema: {
97
- modelName: modelName,
98
- definition: schemaDefinition,
99
- options: options
50
+ if (options.explicitIdentifier && options.implicitIdentifier) {
51
+ throw new Error(`Cannot have both explicit and implicit identifiers in ${modelName}`);
100
52
  }
101
- };
102
- Object.entries(schemaDefinition).forEach(function (_ref) {
103
- var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
104
- slotName = _ref2[0],
105
- slotDefinition = _ref2[1];
106
-
107
- if ((0, _mobxStateTree.isType)(slotDefinition) && (0, _mobxStateTree.isLateType)(slotDefinition) || (0, _util.isConfigurationSchemaType)(slotDefinition)) {
108
- // this is either an MST late() type (which we assume to be a sub-configuration),
109
- // or an actual sub-configuration
110
- modelDefinition[slotName] = slotDefinition;
111
- } else if (typeof slotDefinition === 'string' || typeof slotDefinition === 'number') {
112
- volatileConstants[slotName] = slotDefinition;
113
- } else if ((0, _typeof2.default)(slotDefinition) === 'object') {
114
- // this is a slot definition
115
- if (!slotDefinition.type) {
116
- throw new Error("no type set for config slot ".concat(modelName, ".").concat(slotName));
117
- }
118
-
119
- try {
120
- modelDefinition[slotName] = (0, _configurationSlot.default)(slotName, slotDefinition);
121
- } catch (e) {
122
- throw new Error("invalid config slot definition for ".concat(modelName, ".").concat(slotName, ": ").concat(e));
123
- }
124
- } else {
125
- throw new Error("invalid configuration schema definition, \"".concat(slotName, "\" must be either a valid configuration slot definition, a constant, or a nested configuration schema"));
53
+ if (options.explicitIdentifier) {
54
+ if (typeof options.explicitIdentifier === 'string') {
55
+ modelDefinition[options.explicitIdentifier] = mobx_state_tree_1.types.identifier;
56
+ identifier = options.explicitIdentifier;
57
+ }
58
+ else {
59
+ modelDefinition.id = mobx_state_tree_1.types.identifier;
60
+ identifier = 'id';
61
+ }
126
62
  }
127
- });
128
-
129
- var completeModel = _mobxStateTree.types.model("".concat(modelName, "ConfigurationSchema"), modelDefinition).actions(function (self) {
130
- return {
131
- setSubschema: function setSubschema(slotName, data) {
132
- if (!(0, _util.isConfigurationSchemaType)(modelDefinition[slotName])) {
133
- throw new Error("".concat(slotName, " is not a subschema, cannot replace"));
63
+ else if (options.implicitIdentifier) {
64
+ if (typeof options.implicitIdentifier === 'string') {
65
+ modelDefinition[options.implicitIdentifier] = mst_1.ElementId;
66
+ identifier = options.implicitIdentifier;
67
+ }
68
+ else {
69
+ modelDefinition.id = mst_1.ElementId;
70
+ identifier = 'id';
134
71
  }
135
-
136
- var newSchema = (0, _mobxStateTree.isStateTreeNode)(data) ? data : modelDefinition[slotName].create(data);
137
- self[slotName] = newSchema;
138
- return newSchema;
139
- }
72
+ }
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
+ const volatileConstants = {
75
+ isJBrowseConfigurationSchema: true,
76
+ jbrowseSchema: {
77
+ modelName,
78
+ definition: schemaDefinition,
79
+ options,
80
+ },
140
81
  };
141
- });
142
-
143
- if (Object.keys(volatileConstants).length) {
144
- completeModel = completeModel.volatile(function
145
- /* self */
146
- () {
147
- return volatileConstants;
148
- });
149
- }
150
-
151
- if (options.actions) {
152
- completeModel = completeModel.actions(options.actions);
153
- }
154
-
155
- if (options.views) {
156
- completeModel = completeModel.views(options.views);
157
- }
158
-
159
- if (options.extend) {
160
- completeModel = completeModel.extend(options.extend);
161
- }
162
-
163
- var identifierDefault = identifier ? (0, _defineProperty2.default)({}, identifier, 'placeholderId') : {};
164
- var modelDefault = options.explicitlyTyped ? _objectSpread({
165
- type: modelName
166
- }, identifierDefault) : identifierDefault;
167
- var defaultSnap = (0, _mobxStateTree.getSnapshot)(completeModel.create(modelDefault));
168
- completeModel = completeModel.postProcessSnapshot(function (snap) {
169
- var newSnap = {};
170
- var matchesDefault = true; // let keyCount = 0
171
-
172
- for (var _i = 0, _Object$entries = Object.entries(snap); _i < _Object$entries.length; _i++) {
173
- var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
174
- key = _Object$entries$_i[0],
175
- value = _Object$entries$_i[1];
176
-
177
- if (matchesDefault) {
178
- if ((0, _typeof2.default)(defaultSnap[key]) === 'object' && (0, _typeof2.default)(value) === 'object') {
179
- if (JSON.stringify(defaultSnap[key]) !== JSON.stringify(value)) {
180
- matchesDefault = false;
181
- }
182
- } else if (defaultSnap[key] !== value) {
183
- matchesDefault = false;
82
+ Object.entries(schemaDefinition).forEach(([slotName, slotDefinition]) => {
83
+ if (((0, mobx_state_tree_1.isType)(slotDefinition) && (0, mobx_state_tree_1.isLateType)(slotDefinition)) ||
84
+ (0, util_1.isConfigurationSchemaType)(slotDefinition)) {
85
+ // this is either an MST late() type (which we assume to be a sub-configuration),
86
+ // or an actual sub-configuration
87
+ modelDefinition[slotName] = slotDefinition;
88
+ }
89
+ else if (typeof slotDefinition === 'string' ||
90
+ typeof slotDefinition === 'number') {
91
+ volatileConstants[slotName] = slotDefinition;
92
+ }
93
+ else if (typeof slotDefinition === 'object') {
94
+ // this is a slot definition
95
+ if (!slotDefinition.type) {
96
+ throw new Error(`no type set for config slot ${modelName}.${slotName}`);
97
+ }
98
+ try {
99
+ modelDefinition[slotName] = (0, configurationSlot_1.default)(slotName, slotDefinition);
100
+ }
101
+ catch (e) {
102
+ throw new Error(`invalid config slot definition for ${modelName}.${slotName}: ${e}`);
103
+ }
184
104
  }
185
- }
186
-
187
- if (value !== undefined && volatileConstants[key] === undefined && !isEmptyObject(value) && !isEmptyArray(value)) {
188
- // keyCount += 1
189
- newSnap[key] = value;
190
- }
105
+ else {
106
+ throw new Error(`invalid configuration schema definition, "${slotName}" must be either a valid configuration slot definition, a constant, or a nested configuration schema`);
107
+ }
108
+ });
109
+ let completeModel = mobx_state_tree_1.types
110
+ .model(`${modelName}ConfigurationSchema`, modelDefinition)
111
+ .actions(self => ({
112
+ setSubschema(slotName, data) {
113
+ if (!(0, util_1.isConfigurationSchemaType)(modelDefinition[slotName])) {
114
+ throw new Error(`${slotName} is not a subschema, cannot replace`);
115
+ }
116
+ const newSchema = (0, mobx_state_tree_1.isStateTreeNode)(data)
117
+ ? data
118
+ : modelDefinition[slotName].create(data);
119
+ self[slotName] = newSchema;
120
+ return newSchema;
121
+ },
122
+ }));
123
+ if (Object.keys(volatileConstants).length) {
124
+ completeModel = completeModel.volatile(( /* self */) => volatileConstants);
125
+ }
126
+ if (options.actions) {
127
+ completeModel = completeModel.actions(options.actions);
191
128
  }
192
-
193
- if (matchesDefault) {
194
- return {};
129
+ if (options.views) {
130
+ completeModel = completeModel.views(options.views);
195
131
  }
196
-
197
- return newSnap;
198
- });
199
-
200
- if (options.preProcessSnapshot) {
201
- completeModel = completeModel.preProcessSnapshot(options.preProcessSnapshot);
202
- }
203
-
204
- return _mobxStateTree.types.optional(completeModel, modelDefault);
132
+ if (options.extend) {
133
+ completeModel = completeModel.extend(options.extend);
134
+ }
135
+ const identifierDefault = identifier ? { [identifier]: 'placeholderId' } : {};
136
+ const modelDefault = options.explicitlyTyped
137
+ ? { type: modelName, ...identifierDefault }
138
+ : identifierDefault;
139
+ const defaultSnap = (0, mobx_state_tree_1.getSnapshot)(completeModel.create(modelDefault));
140
+ completeModel = completeModel.postProcessSnapshot(snap => {
141
+ const newSnap = {};
142
+ let matchesDefault = true;
143
+ // let keyCount = 0
144
+ for (const [key, value] of Object.entries(snap)) {
145
+ if (matchesDefault) {
146
+ if (typeof defaultSnap[key] === 'object' && typeof value === 'object') {
147
+ if (JSON.stringify(defaultSnap[key]) !== JSON.stringify(value)) {
148
+ matchesDefault = false;
149
+ }
150
+ }
151
+ else if (defaultSnap[key] !== value) {
152
+ matchesDefault = false;
153
+ }
154
+ }
155
+ if (value !== undefined &&
156
+ volatileConstants[key] === undefined &&
157
+ !isEmptyObject(value) &&
158
+ !isEmptyArray(value)) {
159
+ // keyCount += 1
160
+ newSnap[key] = value;
161
+ }
162
+ }
163
+ if (matchesDefault) {
164
+ return {};
165
+ }
166
+ return newSnap;
167
+ });
168
+ if (options.preProcessSnapshot) {
169
+ completeModel = completeModel.preProcessSnapshot(options.preProcessSnapshot);
170
+ }
171
+ return mobx_state_tree_1.types.optional(completeModel, modelDefault);
205
172
  }
206
-
207
173
  function ConfigurationSchema(modelName, inputSchemaDefinition, inputOptions) {
208
- var _preprocessConfigurat = preprocessConfigurationSchemaArguments(modelName, inputSchemaDefinition, inputOptions),
209
- schemaDefinition = _preprocessConfigurat.schemaDefinition,
210
- options = _preprocessConfigurat.options;
211
-
212
- var schemaType = makeConfigurationSchemaModel(modelName, schemaDefinition, options); // saving a couple of jbrowse-specific things in the type object. hope nobody gets mad.
213
-
214
- schemaType.isJBrowseConfigurationSchema = true;
215
- schemaType.jbrowseSchemaDefinition = schemaDefinition;
216
- schemaType.jbrowseSchemaOptions = options;
217
- return schemaType;
174
+ const { schemaDefinition, options } = preprocessConfigurationSchemaArguments(modelName, inputSchemaDefinition, inputOptions);
175
+ const schemaType = makeConfigurationSchemaModel(modelName, schemaDefinition, options);
176
+ // saving a couple of jbrowse-specific things in the type object. hope nobody gets mad.
177
+ schemaType.isJBrowseConfigurationSchema = true;
178
+ schemaType.jbrowseSchemaDefinition = schemaDefinition;
179
+ schemaType.jbrowseSchemaOptions = options;
180
+ return schemaType;
218
181
  }
219
-
182
+ exports.ConfigurationSchema = ConfigurationSchema;
220
183
  function ConfigurationReference(schemaType) {
221
- return _mobxStateTree.types.union(_mobxStateTree.types.reference(schemaType), schemaType);
222
- }
184
+ return mobx_state_tree_1.types.union(mobx_state_tree_1.types.reference(schemaType), schemaType);
185
+ }
186
+ exports.ConfigurationReference = ConfigurationReference;