@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,352 +1,274 @@
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.default = ConfigSlot;
9
-
10
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
-
12
- var _mobxStateTree = require("mobx-state-tree");
13
-
14
- var _jexlStrings = require("../util/jexlStrings");
15
-
16
- var _mst = require("../util/types/mst");
17
-
2
+ Object.defineProperty(exports, "__esModule", { value: true });
18
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
19
- function
20
- /* str */
21
- isValidColorString() {
22
- // TODO: check all the crazy cases for whether it's a valid HTML/CSS color string
23
- return true;
4
+ const mobx_state_tree_1 = require("mobx-state-tree");
5
+ const jexlStrings_1 = require("../util/jexlStrings");
6
+ const mst_1 = require("../util/types/mst");
7
+ function isValidColorString( /* str */) {
8
+ // TODO: check all the crazy cases for whether it's a valid HTML/CSS color string
9
+ return true;
24
10
  }
25
-
26
- var typeModels = {
27
- stringArray: _mobxStateTree.types.array(_mobxStateTree.types.string),
28
- stringArrayMap: _mobxStateTree.types.map(_mobxStateTree.types.array(_mobxStateTree.types.string)),
29
- numberMap: _mobxStateTree.types.map(_mobxStateTree.types.number),
30
- boolean: _mobxStateTree.types.boolean,
31
- color: _mobxStateTree.types.refinement('Color', _mobxStateTree.types.string, isValidColorString),
32
- integer: _mobxStateTree.types.integer,
33
- number: _mobxStateTree.types.number,
34
- string: _mobxStateTree.types.string,
35
- text: _mobxStateTree.types.string,
36
- fileLocation: _mst.FileLocation,
37
- frozen: _mobxStateTree.types.frozen()
38
- }; // default values we use if the defaultValue is malformed or does not work
39
-
40
- var fallbackDefaults = {
41
- stringArray: [],
42
- stringArrayMap: {},
43
- numberMap: {},
44
- boolean: true,
45
- color: 'black',
46
- integer: 1,
47
- number: 1,
48
- string: '',
49
- text: '',
50
- fileLocation: {
51
- uri: '/path/to/resource.txt',
52
- locationType: 'UriLocation'
53
- },
54
- frozen: {}
11
+ const typeModels = {
12
+ stringArray: mobx_state_tree_1.types.array(mobx_state_tree_1.types.string),
13
+ stringArrayMap: mobx_state_tree_1.types.map(mobx_state_tree_1.types.array(mobx_state_tree_1.types.string)),
14
+ numberMap: mobx_state_tree_1.types.map(mobx_state_tree_1.types.number),
15
+ boolean: mobx_state_tree_1.types.boolean,
16
+ color: mobx_state_tree_1.types.refinement('Color', mobx_state_tree_1.types.string, isValidColorString),
17
+ integer: mobx_state_tree_1.types.integer,
18
+ number: mobx_state_tree_1.types.number,
19
+ string: mobx_state_tree_1.types.string,
20
+ text: mobx_state_tree_1.types.string,
21
+ fileLocation: mst_1.FileLocation,
22
+ frozen: mobx_state_tree_1.types.frozen(),
55
23
  };
56
-
57
- var literalJSON = function literalJSON(self) {
58
- return {
59
- views: {
60
- get valueJSON() {
61
- return self.value;
62
- }
63
-
64
- }
65
- };
24
+ // default values we use if the defaultValue is malformed or does not work
25
+ const fallbackDefaults = {
26
+ stringArray: [],
27
+ stringArrayMap: {},
28
+ numberMap: {},
29
+ boolean: true,
30
+ color: 'black',
31
+ integer: 1,
32
+ number: 1,
33
+ string: '',
34
+ text: '',
35
+ fileLocation: { uri: '/path/to/resource.txt', locationType: 'UriLocation' },
36
+ frozen: {},
66
37
  };
67
-
68
- var objectJSON = function objectJSON(self) {
69
- return {
38
+ const literalJSON = (self) => ({
70
39
  views: {
71
- get valueJSON() {
72
- return JSON.stringify(self.value);
73
- }
74
-
75
- }
76
- };
77
- }; // custom actions for modifying the value models
78
-
79
-
80
- var typeModelExtensions = {
81
- fileLocation: objectJSON,
82
- number: literalJSON,
83
- integer: literalJSON,
84
- boolean: literalJSON,
85
- frozen: objectJSON,
86
- // special actions for working with stringArray slots
87
- stringArray: function stringArray(self) {
88
- return {
89
- views: {
90
40
  get valueJSON() {
91
- return JSON.stringify(self.value);
92
- }
93
-
94
- },
95
- actions: {
96
- add: function add(val) {
97
- self.value.push(val);
98
- },
99
- removeAtIndex: function removeAtIndex(idx) {
100
- self.value.splice(idx, 1);
41
+ return self.value;
101
42
  },
102
- setAtIndex: function setAtIndex(idx, val) {
103
- self.value[idx] = val;
104
- }
105
- }
106
- };
107
- },
108
- stringArrayMap: function stringArrayMap(self) {
109
- return {
110
- views: {
43
+ },
44
+ });
45
+ const objectJSON = (self) => ({
46
+ views: {
111
47
  get valueJSON() {
112
- return JSON.stringify(self.value);
113
- }
114
-
115
- },
116
- actions: {
117
- add: function add(key, val) {
118
- self.value.set(key, val);
48
+ return JSON.stringify(self.value);
119
49
  },
120
- remove: function remove(key) {
121
- self.value.delete(key);
50
+ },
51
+ });
52
+ // custom actions for modifying the value models
53
+ const typeModelExtensions = {
54
+ fileLocation: objectJSON,
55
+ number: literalJSON,
56
+ integer: literalJSON,
57
+ boolean: literalJSON,
58
+ frozen: objectJSON,
59
+ // special actions for working with stringArray slots
60
+ stringArray: (self) => ({
61
+ views: {
62
+ get valueJSON() {
63
+ return JSON.stringify(self.value);
64
+ },
122
65
  },
123
- addToKey: function addToKey(key, val) {
124
- var ar = self.value.get(key);
125
-
126
- if (!ar) {
127
- throw new Error("".concat(key, " not found"));
128
- }
129
-
130
- ar.push(val);
66
+ actions: {
67
+ add(val) {
68
+ self.value.push(val);
69
+ },
70
+ removeAtIndex(idx) {
71
+ self.value.splice(idx, 1);
72
+ },
73
+ setAtIndex(idx, val) {
74
+ self.value[idx] = val;
75
+ },
131
76
  },
132
- removeAtKeyIndex: function removeAtKeyIndex(key, idx) {
133
- var ar = self.value.get(key);
134
-
135
- if (!ar) {
136
- throw new Error("".concat(key, " not found"));
137
- }
138
-
139
- ar.splice(idx, 1);
77
+ }),
78
+ stringArrayMap: (self) => ({
79
+ views: {
80
+ get valueJSON() {
81
+ return JSON.stringify(self.value);
82
+ },
140
83
  },
141
- setAtKeyIndex: function setAtKeyIndex(key, idx, val) {
142
- var ar = self.value.get(key);
143
-
144
- if (!ar) {
145
- throw new Error("".concat(key, " not found"));
146
- }
147
-
148
- ar[idx] = val;
149
- }
150
- }
151
- };
152
- },
153
- numberMap: function numberMap(self) {
154
- return {
155
- views: {
156
- get valueJSON() {
157
- return JSON.stringify(self.value);
158
- }
159
-
160
- },
161
- actions: {
162
- add: function add(key, val) {
163
- self.value.set(key, val);
84
+ actions: {
85
+ add(key, val) {
86
+ self.value.set(key, val);
87
+ },
88
+ remove(key) {
89
+ self.value.delete(key);
90
+ },
91
+ addToKey(key, val) {
92
+ const ar = self.value.get(key);
93
+ if (!ar) {
94
+ throw new Error(`${key} not found`);
95
+ }
96
+ ar.push(val);
97
+ },
98
+ removeAtKeyIndex(key, idx) {
99
+ const ar = self.value.get(key);
100
+ if (!ar) {
101
+ throw new Error(`${key} not found`);
102
+ }
103
+ ar.splice(idx, 1);
104
+ },
105
+ setAtKeyIndex(key, idx, val) {
106
+ const ar = self.value.get(key);
107
+ if (!ar) {
108
+ throw new Error(`${key} not found`);
109
+ }
110
+ ar[idx] = val;
111
+ },
164
112
  },
165
- remove: function remove(key) {
166
- self.value.delete(key);
167
- }
168
- }
169
- };
170
- }
171
- }; // const FunctionStringType = types.refinement(
113
+ }),
114
+ numberMap: (self) => ({
115
+ views: {
116
+ get valueJSON() {
117
+ return JSON.stringify(self.value);
118
+ },
119
+ },
120
+ actions: {
121
+ add(key, val) {
122
+ self.value.set(key, val);
123
+ },
124
+ remove(key) {
125
+ self.value.delete(key);
126
+ },
127
+ },
128
+ }),
129
+ };
130
+ // const FunctionStringType = types.refinement(
172
131
  // 'FunctionString',
173
132
  // types.string,
174
133
  // str => functionRegexp.test(str),
175
134
  // )
176
-
177
- var JexlStringType = _mobxStateTree.types.refinement('JexlString', _mobxStateTree.types.string, function (str) {
178
- return str.startsWith('jexl:');
179
- });
180
-
135
+ const JexlStringType = mobx_state_tree_1.types.refinement('JexlString', mobx_state_tree_1.types.string, str => str.startsWith('jexl:'));
181
136
  /**
182
137
  * builds a MST model for a configuration slot
183
138
  *
184
139
  * @param slotName -
185
140
  * @param definition -
186
141
  */
187
- function ConfigSlot(slotName, _ref) {
188
- var _ref$description = _ref.description,
189
- description = _ref$description === void 0 ? '' : _ref$description,
190
- model = _ref.model,
191
- type = _ref.type,
192
- defaultValue = _ref.defaultValue,
193
- _ref$contextVariable = _ref.contextVariable,
194
- contextVariable = _ref$contextVariable === void 0 ? [] : _ref$contextVariable;
195
-
196
- if (!type) {
197
- throw new Error('type name required');
198
- }
199
-
200
- if (!model) {
201
- model = typeModels[type];
202
- }
203
-
204
- if (!model) {
205
- throw new Error("no builtin config slot type \"".concat(type, "\", and no 'model' param provided"));
206
- }
207
-
208
- if (defaultValue === undefined) {
209
- throw new Error("no 'defaultValue' provided");
210
- } // if the `type` is something like `color`, then the model name
211
- // here will be `ColorConfigSlot`
212
-
213
-
214
- var configSlotModelName = "".concat(slotName.charAt(0).toUpperCase()).concat(slotName.slice(1), "ConfigSlot");
215
-
216
- var slot = _mobxStateTree.types.model(configSlotModelName, {
217
- name: _mobxStateTree.types.literal(slotName),
218
- description: _mobxStateTree.types.literal(description),
219
- type: _mobxStateTree.types.literal(type),
220
- value: _mobxStateTree.types.optional(_mobxStateTree.types.union(JexlStringType, model), defaultValue)
221
- }).volatile(function () {
222
- return {
223
- contextVariable: contextVariable
224
- };
225
- }).views(function (self) {
226
- return {
227
- get isCallback() {
228
- return String(self.value).startsWith('jexl:');
229
- }
230
-
231
- };
232
- }).views(function (self) {
233
- return {
234
- get expr() {
235
- if (self.isCallback) {
236
- // compile as jexl function
237
- var _getEnv = (0, _mobxStateTree.getEnv)(self),
238
- pluginManager = _getEnv.pluginManager;
239
-
240
- if (!pluginManager && typeof jest === 'undefined') {
241
- console.warn('no pluginManager detected on config env (if you dynamically instantiate a config, for example in renderProps for your display model, check that you add the env argument)');
242
- }
243
-
244
- return (0, _jexlStrings.stringToJexlExpression)(String(self.value), pluginManager === null || pluginManager === void 0 ? void 0 : pluginManager.jexl);
245
- }
246
-
247
- return {
248
- evalSync: function evalSync() {
249
- return self.value;
250
- }
251
- };
252
- },
253
-
254
- // JS representation of the value of this slot, suitable
255
- // for embedding in either JSON or a JS function string.
256
- // many of the data types override this in typeModelExtensions
257
- get valueJSON() {
258
- if (self.isCallback) {
259
- return undefined;
260
- }
261
-
262
- function json(value) {
263
- if (value && value.toJSON) {
264
- return value.toJSON();
265
- }
266
-
267
- return "\"".concat(value, "\"");
268
- }
269
-
270
- return json(self.value);
271
- }
272
-
273
- };
274
- }).preProcessSnapshot(function (val) {
275
- return (0, _typeof2.default)(val) === 'object' && val.name === slotName ? val : {
276
- name: slotName,
277
- description: description,
278
- type: type,
279
- value: val
280
- };
281
- }).postProcessSnapshot(function (snap) {
282
- if ((0, _typeof2.default)(snap.value) === 'object') {
283
- return JSON.stringify(snap.value) !== JSON.stringify(defaultValue) ? snap.value : undefined;
142
+ function ConfigSlot(slotName, { description = '', model, type, defaultValue, contextVariable = [], }) {
143
+ if (!type) {
144
+ throw new Error('type name required');
284
145
  }
285
-
286
- return snap.value !== defaultValue ? snap.value : undefined;
287
- }).actions(function (self) {
288
- return {
289
- set: function set(newVal) {
290
- self.value = newVal;
291
- },
292
- reset: function reset() {
293
- self.value = defaultValue;
294
- },
295
- convertToCallback: function convertToCallback() {
296
- if (self.isCallback) {
297
- return;
298
- }
299
-
300
- self.value = "jexl:".concat(self.valueJSON || "''");
301
- },
302
- convertToValue: function convertToValue() {
303
- if (!self.isCallback) {
304
- return;
305
- } // try calling it with no arguments
306
-
307
-
308
- try {
309
- var funcResult = self.expr.evalSync();
310
-
311
- if (funcResult !== undefined) {
312
- self.value = funcResult;
313
- return;
314
- }
315
- } catch (e) {
316
- /* ignore */
317
- }
318
-
319
- self.value = defaultValue; // if it is still a callback (happens if the defaultValue is a callback),
320
- // then use the last-resort fallback default
321
- // if defaultValue has jexl: string, run this part
322
-
323
- if (self.isCallback) {
324
- if (!(type in fallbackDefaults)) {
325
- throw new Error("no fallbackDefault defined for type ".concat(type));
326
- }
327
-
328
- self.value = fallbackDefaults[type];
146
+ if (!model) {
147
+ model = typeModels[type];
148
+ }
149
+ if (!model) {
150
+ throw new Error(`no builtin config slot type "${type}", and no 'model' param provided`);
151
+ }
152
+ if (defaultValue === undefined) {
153
+ throw new Error("no 'defaultValue' provided");
154
+ }
155
+ // if the `type` is something like `color`, then the model name
156
+ // here will be `ColorConfigSlot`
157
+ const configSlotModelName = `${slotName
158
+ .charAt(0)
159
+ .toUpperCase()}${slotName.slice(1)}ConfigSlot`;
160
+ let slot = mobx_state_tree_1.types
161
+ .model(configSlotModelName, {
162
+ name: mobx_state_tree_1.types.literal(slotName),
163
+ description: mobx_state_tree_1.types.literal(description),
164
+ type: mobx_state_tree_1.types.literal(type),
165
+ value: mobx_state_tree_1.types.optional(mobx_state_tree_1.types.union(JexlStringType, model), defaultValue),
166
+ })
167
+ .volatile(() => ({
168
+ contextVariable,
169
+ }))
170
+ .views(self => ({
171
+ get isCallback() {
172
+ return String(self.value).startsWith('jexl:');
173
+ },
174
+ }))
175
+ .views(self => ({
176
+ get expr() {
177
+ if (self.isCallback) {
178
+ // compile as jexl function
179
+ const { pluginManager } = (0, mobx_state_tree_1.getEnv)(self);
180
+ if (!pluginManager && typeof jest === 'undefined') {
181
+ console.warn('no pluginManager detected on config env (if you dynamically instantiate a config, for example in renderProps for your display model, check that you add the env argument)');
182
+ }
183
+ return (0, jexlStrings_1.stringToJexlExpression)(String(self.value), pluginManager === null || pluginManager === void 0 ? void 0 : pluginManager.jexl);
184
+ }
185
+ return { evalSync: () => self.value };
186
+ },
187
+ // JS representation of the value of this slot, suitable
188
+ // for embedding in either JSON or a JS function string.
189
+ // many of the data types override this in typeModelExtensions
190
+ get valueJSON() {
191
+ if (self.isCallback) {
192
+ return undefined;
193
+ }
194
+ function json(value) {
195
+ if (value && value.toJSON) {
196
+ return value.toJSON();
197
+ }
198
+ return `"${value}"`;
199
+ }
200
+ return json(self.value);
201
+ },
202
+ }))
203
+ .preProcessSnapshot(val => typeof val === 'object' && val.name === slotName
204
+ ? val
205
+ : {
206
+ name: slotName,
207
+ description,
208
+ type,
209
+ value: val,
210
+ })
211
+ .postProcessSnapshot(snap => {
212
+ if (typeof snap.value === 'object') {
213
+ return JSON.stringify(snap.value) !== JSON.stringify(defaultValue)
214
+ ? snap.value
215
+ : undefined;
329
216
  }
330
- }
331
- };
332
- }); // if there are any type-specific extensions (views or actions)
333
- // to the slot, add those in
334
-
335
-
336
- if (typeModelExtensions[type]) {
337
- slot = slot.extend(typeModelExtensions[type]);
338
- }
339
-
340
- var completeModel = _mobxStateTree.types.optional(slot, {
341
- name: slotName,
342
- type: type,
343
- description: description,
344
- value: defaultValue
345
- });
346
-
347
- var m = completeModel;
348
- Object.defineProperty(m, 'isJBrowseConfigurationSlot', {
349
- value: true
350
- });
351
- return m;
352
- }
217
+ return snap.value !== defaultValue ? snap.value : undefined;
218
+ })
219
+ .actions(self => ({
220
+ set(newVal) {
221
+ self.value = newVal;
222
+ },
223
+ reset() {
224
+ self.value = defaultValue;
225
+ },
226
+ convertToCallback() {
227
+ if (self.isCallback) {
228
+ return;
229
+ }
230
+ self.value = `jexl:${self.valueJSON || "''"}`;
231
+ },
232
+ convertToValue() {
233
+ if (!self.isCallback) {
234
+ return;
235
+ }
236
+ // try calling it with no arguments
237
+ try {
238
+ const funcResult = self.expr.evalSync();
239
+ if (funcResult !== undefined) {
240
+ self.value = funcResult;
241
+ return;
242
+ }
243
+ }
244
+ catch (e) {
245
+ /* ignore */
246
+ }
247
+ self.value = defaultValue;
248
+ // if it is still a callback (happens if the defaultValue is a callback),
249
+ // then use the last-resort fallback default
250
+ // if defaultValue has jexl: string, run this part
251
+ if (self.isCallback) {
252
+ if (!(type in fallbackDefaults)) {
253
+ throw new Error(`no fallbackDefault defined for type ${type}`);
254
+ }
255
+ self.value = fallbackDefaults[type];
256
+ }
257
+ },
258
+ }));
259
+ // if there are any type-specific extensions (views or actions)
260
+ // to the slot, add those in
261
+ if (typeModelExtensions[type]) {
262
+ slot = slot.extend(typeModelExtensions[type]);
263
+ }
264
+ const completeModel = mobx_state_tree_1.types.optional(slot, {
265
+ name: slotName,
266
+ type,
267
+ description,
268
+ value: defaultValue,
269
+ });
270
+ const m = completeModel;
271
+ Object.defineProperty(m, 'isJBrowseConfigurationSlot', { value: true });
272
+ return m;
273
+ }
274
+ exports.default = ConfigSlot;
@@ -1,37 +1,21 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- ConfigurationSchema: true,
8
- ConfigurationReference: true
9
- };
10
- Object.defineProperty(exports, "ConfigurationReference", {
11
- enumerable: true,
12
- get: function get() {
13
- return _configurationSchema.ConfigurationReference;
14
- }
15
- });
16
- Object.defineProperty(exports, "ConfigurationSchema", {
17
- enumerable: true,
18
- get: function get() {
19
- return _configurationSchema.ConfigurationSchema;
20
- }
21
- });
22
-
23
- var _configurationSchema = require("./configurationSchema");
24
-
25
- var _util = require("./util");
26
-
27
- Object.keys(_util).forEach(function (key) {
28
- if (key === "default" || key === "__esModule") return;
29
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
30
- if (key in exports && exports[key] === _util[key]) return;
31
- Object.defineProperty(exports, key, {
32
- enumerable: true,
33
- get: function get() {
34
- return _util[key];
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
35
7
  }
36
- });
37
- });
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ConfigurationReference = exports.ConfigurationSchema = void 0;
18
+ var configurationSchema_1 = require("./configurationSchema");
19
+ Object.defineProperty(exports, "ConfigurationSchema", { enumerable: true, get: function () { return configurationSchema_1.ConfigurationSchema; } });
20
+ Object.defineProperty(exports, "ConfigurationReference", { enumerable: true, get: function () { return configurationSchema_1.ConfigurationReference; } });
21
+ __exportStar(require("./util"), exports);