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