@jbrowse/core 2.0.0 → 2.1.2

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 (184) hide show
  1. package/BaseFeatureWidget/BaseFeatureDetail.d.ts +9 -3
  2. package/BaseFeatureWidget/BaseFeatureDetail.js +313 -581
  3. package/BaseFeatureWidget/SequenceFeatureDetails.js +213 -478
  4. package/BaseFeatureWidget/index.js +88 -126
  5. package/BaseFeatureWidget/types.d.ts +1 -0
  6. package/BaseFeatureWidget/types.js +1 -4
  7. package/BaseFeatureWidget/util.js +40 -75
  8. package/CorePlugin.js +55 -94
  9. package/Plugin.js +9 -34
  10. package/PluginLoader.js +153 -422
  11. package/PluginManager.d.ts +28 -33
  12. package/PluginManager.js +377 -666
  13. package/ReExports/Attributes.js +3 -10
  14. package/ReExports/BaseCard.js +3 -10
  15. package/ReExports/DataGrid.js +5 -12
  16. package/ReExports/FeatureDetails.js +3 -10
  17. package/ReExports/index.js +6 -12
  18. package/ReExports/list.d.ts +5 -0
  19. package/ReExports/list.js +271 -7
  20. package/ReExports/material-ui-colors.js +15 -16
  21. package/ReExports/modules.d.ts +11 -20
  22. package/ReExports/modules.js +453 -798
  23. package/TextSearch/BaseResults.js +51 -123
  24. package/TextSearch/TextSearchManager.js +66 -144
  25. package/assemblyManager/assembly.js +280 -555
  26. package/assemblyManager/assemblyConfigSchema.js +47 -64
  27. package/assemblyManager/assemblyManager.js +126 -272
  28. package/assemblyManager/index.js +9 -22
  29. package/configuration/configurationSchema.js +167 -203
  30. package/configuration/configurationSlot.js +248 -326
  31. package/configuration/index.js +19 -35
  32. package/configuration/util.js +131 -173
  33. package/data_adapters/BaseAdapter.d.ts +2 -2
  34. package/data_adapters/BaseAdapter.js +132 -521
  35. package/data_adapters/CytobandAdapter.js +40 -126
  36. package/data_adapters/dataAdapterCache.js +77 -158
  37. package/package.json +4 -5
  38. package/pluggableElementTypes/AdapterType.js +24 -79
  39. package/pluggableElementTypes/AddTrackWorkflowType.d.ts +17 -0
  40. package/pluggableElementTypes/AddTrackWorkflowType.js +20 -0
  41. package/pluggableElementTypes/ConnectionType.js +22 -65
  42. package/pluggableElementTypes/DisplayType.js +35 -82
  43. package/pluggableElementTypes/InternetAccountType.js +23 -64
  44. package/pluggableElementTypes/PluggableElementBase.js +8 -20
  45. package/pluggableElementTypes/RpcMethodType.js +85 -427
  46. package/pluggableElementTypes/TextSearchAdapterType.js +16 -55
  47. package/pluggableElementTypes/TrackType.js +26 -70
  48. package/pluggableElementTypes/ViewType.js +21 -63
  49. package/pluggableElementTypes/WidgetType.js +21 -64
  50. package/pluggableElementTypes/index.d.ts +4 -3
  51. package/pluggableElementTypes/index.js +42 -125
  52. package/pluggableElementTypes/models/BaseConnectionModelFactory.js +28 -43
  53. package/pluggableElementTypes/models/BaseDisplayModel.js +58 -95
  54. package/pluggableElementTypes/models/BaseTrackModel.js +139 -199
  55. package/pluggableElementTypes/models/BaseViewModel.js +24 -40
  56. package/pluggableElementTypes/models/InternetAccountModel.js +116 -263
  57. package/pluggableElementTypes/models/baseConnectionConfig.js +14 -25
  58. package/pluggableElementTypes/models/baseInternetAccountConfig.js +29 -38
  59. package/pluggableElementTypes/models/baseTrackConfig.js +106 -133
  60. package/pluggableElementTypes/models/index.js +21 -70
  61. package/pluggableElementTypes/renderers/BoxRendererType.js +132 -291
  62. package/pluggableElementTypes/renderers/CircularChordRendererType.js +8 -38
  63. package/pluggableElementTypes/renderers/ComparativeServerSideRendererType.js +60 -192
  64. package/pluggableElementTypes/renderers/FeatureRendererType.d.ts +0 -2
  65. package/pluggableElementTypes/renderers/FeatureRendererType.js +89 -255
  66. package/pluggableElementTypes/renderers/RendererType.js +31 -105
  67. package/pluggableElementTypes/renderers/ServerSideRenderedContent.js +61 -72
  68. package/pluggableElementTypes/renderers/ServerSideRendererType.js +112 -265
  69. package/pluggableElementTypes/renderers/index.js +19 -62
  70. package/pluggableElementTypes/renderers/util/serializableFilterChain.js +27 -65
  71. package/rpc/BaseRpcDriver.js +169 -405
  72. package/rpc/MainThreadRpcDriver.js +27 -150
  73. package/rpc/RpcManager.js +58 -159
  74. package/rpc/WebWorkerRpcDriver.js +54 -171
  75. package/rpc/configSchema.js +25 -49
  76. package/rpc/coreRpcMethods.d.ts +1 -3
  77. package/rpc/coreRpcMethods.js +221 -959
  78. package/rpc/remoteAbortSignals.js +46 -70
  79. package/tsconfig.build.tsbuildinfo +1 -1
  80. package/ui/AboutDialog.js +106 -162
  81. package/ui/App.js +157 -242
  82. package/ui/AssemblySelector.js +59 -120
  83. package/ui/CascadingMenu.js +101 -196
  84. package/ui/ColorPicker.d.ts +16 -0
  85. package/ui/ColorPicker.js +97 -0
  86. package/ui/Drawer.js +28 -61
  87. package/ui/DrawerWidget.js +108 -202
  88. package/ui/DropDownMenu.js +60 -91
  89. package/ui/EditableTypography.js +87 -149
  90. package/ui/ErrorMessage.js +41 -56
  91. package/ui/FactoryResetDialog.js +24 -57
  92. package/ui/FatalErrorDialog.js +59 -91
  93. package/ui/FileSelector/FileSelector.js +123 -189
  94. package/ui/FileSelector/LocalFileChooser.js +44 -75
  95. package/ui/FileSelector/UrlChooser.js +17 -38
  96. package/ui/FileSelector/index.js +6 -12
  97. package/ui/Icons.js +45 -69
  98. package/ui/Logo.js +57 -110
  99. package/ui/Menu.js +232 -354
  100. package/ui/PrerenderedCanvas.js +63 -87
  101. package/ui/ResizeHandle.js +87 -116
  102. package/ui/ReturnToImportFormDialog.js +32 -63
  103. package/ui/SanitizedHTML.js +64 -47
  104. package/ui/Snackbar.js +74 -101
  105. package/ui/SnackbarModel.js +37 -51
  106. package/ui/Tooltip.js +49 -76
  107. package/ui/ViewContainer.js +113 -196
  108. package/ui/colors.d.ts +10 -0
  109. package/ui/colors.js +78 -0
  110. package/ui/index.js +51 -181
  111. package/ui/react-colorful.d.ts +17 -0
  112. package/ui/react-colorful.js +455 -0
  113. package/ui/theme.d.ts +23 -1
  114. package/ui/theme.js +199 -247
  115. package/util/Base1DUtils.d.ts +32 -0
  116. package/util/Base1DUtils.js +174 -0
  117. package/util/Base1DViewModel.d.ts +16 -30
  118. package/util/Base1DViewModel.js +116 -293
  119. package/util/QuickLRU.js +84 -332
  120. package/util/TimeTraveller.d.ts +19 -0
  121. package/util/TimeTraveller.js +86 -0
  122. package/util/aborting.js +49 -127
  123. package/util/analytics.js +91 -154
  124. package/util/blockTypes.js +106 -240
  125. package/util/calculateDynamicBlocks.js +98 -128
  126. package/util/calculateStaticBlocks.js +105 -125
  127. package/util/color/cssColorsLevel4.js +156 -160
  128. package/util/color/index.js +33 -55
  129. package/util/compositeMap.js +49 -333
  130. package/util/formatFastaStrings.js +9 -14
  131. package/util/idMaker.js +18 -31
  132. package/util/index.d.ts +18 -32
  133. package/util/index.js +747 -1226
  134. package/util/io/RemoteFileWithRangeCache.js +88 -257
  135. package/util/io/index.js +95 -169
  136. package/util/jexl.js +60 -115
  137. package/util/jexlStrings.js +24 -29
  138. package/util/layouts/BaseLayout.js +1 -4
  139. package/util/layouts/GranularRectLayout.js +388 -555
  140. package/util/layouts/MultiLayout.js +41 -109
  141. package/util/layouts/PrecomputedLayout.js +56 -112
  142. package/util/layouts/PrecomputedMultiLayout.js +22 -59
  143. package/util/layouts/SceneGraph.js +127 -197
  144. package/util/layouts/index.js +29 -66
  145. package/util/mst-reflection.js +55 -71
  146. package/util/offscreenCanvasPonyfill.js +66 -134
  147. package/util/offscreenCanvasUtils.d.ts +2 -7
  148. package/util/offscreenCanvasUtils.js +49 -146
  149. package/util/range.js +29 -40
  150. package/util/rxjs.js +20 -27
  151. package/util/simpleFeature.js +88 -152
  152. package/util/stats.js +91 -151
  153. package/util/tracks.js +130 -173
  154. package/util/types/index.js +110 -179
  155. package/util/types/mst.js +91 -146
  156. package/util/types/util.js +1 -4
  157. package/util/when.js +54 -101
  158. package/BaseFeatureWidget/SequenceFeatureDetails.test.js +0 -122
  159. package/BaseFeatureWidget/index.test.js +0 -69
  160. package/TextSearch/BaseResults.test.js +0 -42
  161. package/configuration/configurationSchema.test.js +0 -266
  162. package/configuration/configurationSlot.test.js +0 -69
  163. package/configuration/util.test.js +0 -39
  164. package/data_adapters/BaseAdapter.test.js +0 -200
  165. package/declare.d.js +0 -1
  166. package/pluggableElementTypes/RpcMethodType.test.js +0 -118
  167. package/pluggableElementTypes/renderers/declare.d.js +0 -1
  168. package/pluggableElementTypes/renderers/util/serializableFilterChain.test.js +0 -20
  169. package/rpc/BaseRpcDriver.test.js +0 -540
  170. package/rpc/declaration.d.js +0 -1
  171. package/ui/FatalErrorDialog.test.js +0 -82
  172. package/ui/SanitizedHTML.test.js +0 -36
  173. package/ui/theme.test.js +0 -92
  174. package/util/Base1DViewModel.test.js +0 -130
  175. package/util/calculateDynamicBlocks.test.js +0 -74
  176. package/util/calculateStaticBlocks.test.js +0 -297
  177. package/util/declare.d.js +0 -1
  178. package/util/formatFastaStrings.test.js +0 -40
  179. package/util/index.test.js +0 -213
  180. package/util/jexlStrings.test.js +0 -48
  181. package/util/layouts/GranularRectLayout.test.js +0 -99
  182. package/util/range.test.js +0 -64
  183. package/util/simpleFeature.test.js +0 -34
  184. 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);