@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
package/PluginLoader.js CHANGED
@@ -1,438 +1,169 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
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.isCJSPluginDefinition = exports.isESMPluginDefinition = exports.isUMDPluginDefinition = exports.PluginSourceConfigurationSchema = void 0;
7
+ const load_script2_1 = __importDefault(require("load-script2"));
8
+ const configuration_1 = require("./configuration");
9
+ const ReExports_1 = __importDefault(require("./ReExports"));
10
+ const util_1 = require("./util");
11
+ exports.PluginSourceConfigurationSchema = (0, configuration_1.ConfigurationSchema)('PluginSource', {
12
+ name: {
13
+ type: 'string',
14
+ defaultValue: '',
15
+ },
16
+ url: {
17
+ type: 'string',
18
+ defaultValue: '',
19
+ },
7
20
  });
8
- exports.default = exports.PluginSourceConfigurationSchema = void 0;
9
- exports.isCJSPluginDefinition = isCJSPluginDefinition;
10
- exports.isESMPluginDefinition = isESMPluginDefinition;
11
- exports.isUMDPluginDefinition = isUMDPluginDefinition;
12
-
13
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
-
15
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
16
-
17
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
18
-
19
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
20
-
21
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
22
-
23
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
24
-
25
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
26
-
27
- var _loadScript = _interopRequireDefault(require("load-script2"));
28
-
29
- var _configuration = require("./configuration");
30
-
31
- var _ReExports = _interopRequireDefault(require("./ReExports"));
32
-
33
- var _util = require("./util");
34
-
35
- var PluginSourceConfigurationSchema = (0, _configuration.ConfigurationSchema)('PluginSource', {
36
- name: {
37
- type: 'string',
38
- defaultValue: ''
39
- },
40
- url: {
41
- type: 'string',
42
- defaultValue: ''
43
- }
44
- });
45
- exports.PluginSourceConfigurationSchema = PluginSourceConfigurationSchema;
46
-
47
21
  function isUMDPluginDefinition(pluginDefinition) {
48
- return (pluginDefinition.umdUrl !== undefined || pluginDefinition.url !== undefined) && pluginDefinition.name !== undefined;
22
+ return ((pluginDefinition.umdUrl !== undefined ||
23
+ pluginDefinition.url !== undefined) &&
24
+ pluginDefinition
25
+ .name !== undefined);
49
26
  }
50
-
27
+ exports.isUMDPluginDefinition = isUMDPluginDefinition;
51
28
  function isESMPluginDefinition(pluginDefinition) {
52
- return pluginDefinition.esmUrl !== undefined;
29
+ return pluginDefinition.esmUrl !== undefined;
53
30
  }
54
-
31
+ exports.isESMPluginDefinition = isESMPluginDefinition;
55
32
  function isCJSPluginDefinition(pluginDefinition) {
56
- return pluginDefinition.cjsUrl !== undefined;
33
+ return pluginDefinition.cjsUrl !== undefined;
57
34
  }
58
-
35
+ exports.isCJSPluginDefinition = isCJSPluginDefinition;
59
36
  function getGlobalObject() {
60
- // Based on window-or-global
61
- // https://github.com/purposeindustries/window-or-global/blob/322abc71de0010c9e5d9d0729df40959e1ef8775/lib/index.js
62
- return (// eslint-disable-next-line no-restricted-globals
63
- (typeof self === "undefined" ? "undefined" : (0, _typeof2.default)(self)) === 'object' && self.self === self && self || (typeof global === "undefined" ? "undefined" : (0, _typeof2.default)(global)) === 'object' && global.global === global && global || // @ts-ignore
64
- this
65
- );
37
+ // Based on window-or-global
38
+ // https://github.com/purposeindustries/window-or-global/blob/322abc71de0010c9e5d9d0729df40959e1ef8775/lib/index.js
39
+ return (
40
+ // eslint-disable-next-line no-restricted-globals
41
+ (typeof self === 'object' && self.self === self && self) ||
42
+ (typeof global === 'object' && global.global === global && global) ||
43
+ // @ts-ignore
44
+ this);
66
45
  }
67
-
68
46
  function isInWebWorker(globalObject) {
69
- return Boolean('WorkerGlobalScope' in globalObject);
47
+ return Boolean('WorkerGlobalScope' in globalObject);
70
48
  }
71
-
72
- var PluginLoader = /*#__PURE__*/function () {
73
- function PluginLoader() {
74
- var pluginDefinitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
75
- var args = arguments.length > 1 ? arguments[1] : undefined;
76
- (0, _classCallCheck2.default)(this, PluginLoader);
77
- (0, _defineProperty2.default)(this, "definitions", []);
78
- (0, _defineProperty2.default)(this, "fetchESM", void 0);
79
- (0, _defineProperty2.default)(this, "fetchCJS", void 0);
80
- this.fetchESM = args === null || args === void 0 ? void 0 : args.fetchESM;
81
- this.fetchCJS = args === null || args === void 0 ? void 0 : args.fetchCJS;
82
- this.definitions = JSON.parse(JSON.stringify(pluginDefinitions));
83
- }
84
-
85
- (0, _createClass2.default)(PluginLoader, [{
86
- key: "loadScript",
87
- value: function loadScript(scriptUrl) {
88
- var globalObject = getGlobalObject();
89
-
90
- if (!isInWebWorker(globalObject)) {
91
- return (0, _loadScript.default)(scriptUrl);
92
- } // @ts-ignore
93
-
94
-
95
- if (globalObject && globalObject.importScripts) {
96
- return new Promise(function (resolve, reject) {
97
- try {
98
- // @ts-ignore
99
- globalObject.importScripts(scriptUrl);
100
- } catch (error) {
101
- reject(error || new Error("failed to load ".concat(scriptUrl)));
102
- return;
103
- }
104
-
105
- resolve();
106
- });
107
- }
108
-
109
- throw new Error('cannot figure out how to load external JS scripts in this environment');
49
+ class PluginLoader {
50
+ constructor(pluginDefinitions = [], args) {
51
+ this.definitions = [];
52
+ this.fetchESM = args === null || args === void 0 ? void 0 : args.fetchESM;
53
+ this.fetchCJS = args === null || args === void 0 ? void 0 : args.fetchCJS;
54
+ this.definitions = JSON.parse(JSON.stringify(pluginDefinitions));
110
55
  }
111
- }, {
112
- key: "loadCJSPlugin",
113
- value: function () {
114
- var _loadCJSPlugin = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
115
- var cjsUrl, parsedUrl;
116
- return _regenerator.default.wrap(function _callee$(_context) {
117
- while (1) {
118
- switch (_context.prev = _context.next) {
119
- case 0:
120
- cjsUrl = _ref.cjsUrl;
121
- _context.prev = 1;
122
- parsedUrl = new URL(cjsUrl, getGlobalObject().location.href);
123
- _context.next = 9;
124
- break;
125
-
126
- case 5:
127
- _context.prev = 5;
128
- _context.t0 = _context["catch"](1);
129
- console.error(_context.t0);
130
- throw new Error("Error parsing URL: ".concat(cjsUrl));
131
-
132
- case 9:
133
- if (!(parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:')) {
134
- _context.next = 11;
135
- break;
136
- }
137
-
138
- throw new Error("Cannot load plugins using protocol \"".concat(parsedUrl.protocol, "\""));
139
-
140
- case 11:
141
- if (this.fetchCJS) {
142
- _context.next = 13;
143
- break;
144
- }
145
-
146
- throw new Error('No fetchCJS callback provided');
147
-
148
- case 13:
149
- return _context.abrupt("return", this.fetchCJS(parsedUrl.href));
150
-
151
- case 14:
152
- case "end":
153
- return _context.stop();
154
- }
155
- }
156
- }, _callee, this, [[1, 5]]);
157
- }));
158
-
159
- function loadCJSPlugin(_x) {
160
- return _loadCJSPlugin.apply(this, arguments);
161
- }
162
-
163
- return loadCJSPlugin;
164
- }()
165
- }, {
166
- key: "loadESMPlugin",
167
- value: function () {
168
- var _loadESMPlugin = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(pluginDefinition) {
169
- var _this$fetchESM;
170
-
171
- var parsedUrl, plugin;
172
- return _regenerator.default.wrap(function _callee2$(_context2) {
173
- while (1) {
174
- switch (_context2.prev = _context2.next) {
175
- case 0:
176
- _context2.prev = 0;
177
- parsedUrl = new URL(pluginDefinition.esmUrl, getGlobalObject().location.href);
178
- _context2.next = 8;
179
- break;
180
-
181
- case 4:
182
- _context2.prev = 4;
183
- _context2.t0 = _context2["catch"](0);
184
- console.error(_context2.t0);
185
- throw new Error("Error parsing URL: ".concat(pluginDefinition.esmUrl));
186
-
187
- case 8:
188
- if (!(parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:')) {
189
- _context2.next = 10;
190
- break;
191
- }
192
-
193
- throw new Error("cannot load plugins using protocol \"".concat(parsedUrl.protocol, "\""));
194
-
195
- case 10:
196
- _context2.next = 12;
197
- return (_this$fetchESM = this.fetchESM) === null || _this$fetchESM === void 0 ? void 0 : _this$fetchESM.call(this, parsedUrl.href);
198
-
199
- case 12:
200
- plugin = _context2.sent;
201
-
202
- if (plugin) {
203
- _context2.next = 15;
204
- break;
205
- }
206
-
207
- throw new Error("Could not load ESM plugin: ".concat(parsedUrl));
208
-
209
- case 15:
210
- return _context2.abrupt("return", plugin);
211
-
212
- case 16:
213
- case "end":
214
- return _context2.stop();
215
- }
216
- }
217
- }, _callee2, this, [[0, 4]]);
218
- }));
219
-
220
- function loadESMPlugin(_x2) {
221
- return _loadESMPlugin.apply(this, arguments);
222
- }
223
-
224
- return loadESMPlugin;
225
- }()
226
- }, {
227
- key: "loadUMDPlugin",
228
- value: function () {
229
- var _loadUMDPlugin = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(pluginDefinition) {
230
- var umdUrl, parsedUrl, moduleName, umdName, globalObject, plugin;
231
- return _regenerator.default.wrap(function _callee3$(_context3) {
232
- while (1) {
233
- switch (_context3.prev = _context3.next) {
234
- case 0:
235
- umdUrl = 'url' in pluginDefinition ? pluginDefinition.url : pluginDefinition.umdUrl;
236
- _context3.prev = 1;
237
- parsedUrl = new URL(umdUrl, getGlobalObject().location.href);
238
- _context3.next = 9;
239
- break;
240
-
241
- case 5:
242
- _context3.prev = 5;
243
- _context3.t0 = _context3["catch"](1);
244
- console.error(_context3.t0);
245
- throw new Error("Error parsing URL: ".concat(umdUrl));
246
-
247
- case 9:
248
- if (!(parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:')) {
249
- _context3.next = 11;
250
- break;
56
+ loadScript(scriptUrl) {
57
+ const globalObject = getGlobalObject();
58
+ if (!isInWebWorker(globalObject)) {
59
+ return (0, load_script2_1.default)(scriptUrl);
60
+ }
61
+ // @ts-ignore
62
+ if (globalObject && globalObject.importScripts) {
63
+ return new Promise((resolve, reject) => {
64
+ try {
65
+ // @ts-ignore
66
+ globalObject.importScripts(scriptUrl);
251
67
  }
252
-
253
- throw new Error("cannot load plugins using protocol \"".concat(parsedUrl.protocol, "\""));
254
-
255
- case 11:
256
- _context3.next = 13;
257
- return this.loadScript(parsedUrl.href);
258
-
259
- case 13:
260
- moduleName = pluginDefinition.name;
261
- umdName = "JBrowsePlugin".concat(moduleName);
262
- globalObject = getGlobalObject(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
263
-
264
- plugin = globalObject[umdName];
265
-
266
- if (plugin) {
267
- _context3.next = 19;
268
- break;
68
+ catch (error) {
69
+ reject(error || new Error(`failed to load ${scriptUrl}`));
70
+ return;
269
71
  }
270
-
271
- throw new Error("Failed to load UMD bundle for ".concat(moduleName, ", ").concat(globalObject.constructor.name, ".").concat(umdName, " is undefined"));
272
-
273
- case 19:
274
- return _context3.abrupt("return", plugin);
275
-
276
- case 20:
277
- case "end":
278
- return _context3.stop();
279
- }
280
- }
281
- }, _callee3, this, [[1, 5]]);
282
- }));
283
-
284
- function loadUMDPlugin(_x3) {
285
- return _loadUMDPlugin.apply(this, arguments);
286
- }
287
-
288
- return loadUMDPlugin;
289
- }()
290
- }, {
291
- key: "loadPlugin",
292
- value: function () {
293
- var _loadPlugin = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(definition) {
294
- var plugin;
295
- return _regenerator.default.wrap(function _callee4$(_context4) {
296
- while (1) {
297
- switch (_context4.prev = _context4.next) {
298
- case 0:
299
- if (!(_util.isElectron && isCJSPluginDefinition(definition))) {
300
- _context4.next = 6;
301
- break;
302
- }
303
-
304
- _context4.next = 3;
305
- return this.loadCJSPlugin(definition);
306
-
307
- case 3:
308
- plugin = _context4.sent;
309
- _context4.next = 23;
310
- break;
311
-
312
- case 6:
313
- if (!isESMPluginDefinition(definition)) {
314
- _context4.next = 12;
315
- break;
316
- }
317
-
318
- _context4.next = 9;
319
- return this.loadESMPlugin(definition);
320
-
321
- case 9:
322
- plugin = _context4.sent;
323
- _context4.next = 23;
324
- break;
325
-
326
- case 12:
327
- if (!isUMDPluginDefinition(definition)) {
328
- _context4.next = 18;
329
- break;
330
- }
331
-
332
- _context4.next = 15;
333
- return this.loadUMDPlugin(definition);
334
-
335
- case 15:
336
- plugin = _context4.sent;
337
- _context4.next = 23;
338
- break;
339
-
340
- case 18:
341
- if (!(!_util.isElectron && isCJSPluginDefinition(definition))) {
342
- _context4.next = 22;
343
- break;
344
- }
345
-
346
- throw new Error("Only CommonJS plugin found, but not in a NodeJS environment: ".concat(JSON.stringify(definition)));
347
-
348
- case 22:
349
- throw new Error("Could not determine plugin type: ".concat(JSON.stringify(definition)));
350
-
351
- case 23:
352
- return _context4.abrupt("return", plugin.default);
353
-
354
- case 24:
355
- case "end":
356
- return _context4.stop();
357
- }
358
- }
359
- }, _callee4, this);
360
- }));
361
-
362
- function loadPlugin(_x4) {
363
- return _loadPlugin.apply(this, arguments);
364
- }
365
-
366
- return loadPlugin;
367
- }()
368
- }, {
369
- key: "installGlobalReExports",
370
- value: function installGlobalReExports(target) {
371
- // @ts-ignore
372
- target.JBrowseExports = Object.fromEntries(Object.entries(_ReExports.default).map(function (_ref2) {
373
- var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
374
- moduleName = _ref3[0],
375
- module = _ref3[1];
376
-
377
- return [moduleName, module];
378
- }));
72
+ resolve();
73
+ });
74
+ }
75
+ throw new Error('cannot figure out how to load external JS scripts in this environment');
76
+ }
77
+ async loadCJSPlugin({ cjsUrl }) {
78
+ let parsedUrl;
79
+ try {
80
+ parsedUrl = new URL(cjsUrl, getGlobalObject().location.href);
81
+ }
82
+ catch (error) {
83
+ console.error(error);
84
+ throw new Error(`Error parsing URL: ${cjsUrl}`);
85
+ }
86
+ if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
87
+ throw new Error(`Cannot load plugins using protocol "${parsedUrl.protocol}"`);
88
+ }
89
+ if (!this.fetchCJS) {
90
+ throw new Error('No fetchCJS callback provided');
91
+ }
92
+ return this.fetchCJS(parsedUrl.href);
93
+ }
94
+ async loadESMPlugin(pluginDefinition) {
95
+ var _a;
96
+ let parsedUrl;
97
+ try {
98
+ parsedUrl = new URL(pluginDefinition.esmUrl, getGlobalObject().location.href);
99
+ }
100
+ catch (error) {
101
+ console.error(error);
102
+ throw new Error(`Error parsing URL: ${pluginDefinition.esmUrl}`);
103
+ }
104
+ if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
105
+ throw new Error(`cannot load plugins using protocol "${parsedUrl.protocol}"`);
106
+ }
107
+ const plugin = (await ((_a = this.fetchESM) === null || _a === void 0 ? void 0 : _a.call(this, parsedUrl.href)));
108
+ if (!plugin) {
109
+ throw new Error(`Could not load ESM plugin: ${parsedUrl}`);
110
+ }
111
+ return plugin;
379
112
  }
380
- }, {
381
- key: "load",
382
- value: function () {
383
- var _load = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6() {
384
- var _this = this;
385
-
386
- return _regenerator.default.wrap(function _callee6$(_context6) {
387
- while (1) {
388
- switch (_context6.prev = _context6.next) {
389
- case 0:
390
- return _context6.abrupt("return", Promise.all(this.definitions.map( /*#__PURE__*/function () {
391
- var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(definition) {
392
- return _regenerator.default.wrap(function _callee5$(_context5) {
393
- while (1) {
394
- switch (_context5.prev = _context5.next) {
395
- case 0:
396
- _context5.next = 2;
397
- return _this.loadPlugin(definition);
398
-
399
- case 2:
400
- _context5.t0 = _context5.sent;
401
- _context5.t1 = definition;
402
- return _context5.abrupt("return", {
403
- plugin: _context5.t0,
404
- definition: _context5.t1
405
- });
406
-
407
- case 5:
408
- case "end":
409
- return _context5.stop();
410
- }
411
- }
412
- }, _callee5);
413
- }));
414
-
415
- return function (_x5) {
416
- return _ref4.apply(this, arguments);
417
- };
418
- }())));
419
-
420
- case 1:
421
- case "end":
422
- return _context6.stop();
423
- }
424
- }
425
- }, _callee6, this);
426
- }));
427
-
428
- function load() {
429
- return _load.apply(this, arguments);
430
- }
431
-
432
- return load;
433
- }()
434
- }]);
435
- return PluginLoader;
436
- }();
437
-
438
- exports.default = PluginLoader;
113
+ async loadUMDPlugin(pluginDefinition) {
114
+ const umdUrl = 'url' in pluginDefinition ? pluginDefinition.url : pluginDefinition.umdUrl;
115
+ let parsedUrl;
116
+ try {
117
+ parsedUrl = new URL(umdUrl, getGlobalObject().location.href);
118
+ }
119
+ catch (error) {
120
+ console.error(error);
121
+ throw new Error(`Error parsing URL: ${umdUrl}`);
122
+ }
123
+ if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
124
+ throw new Error(`cannot load plugins using protocol "${parsedUrl.protocol}"`);
125
+ }
126
+ await this.loadScript(parsedUrl.href);
127
+ const moduleName = pluginDefinition.name;
128
+ const umdName = `JBrowsePlugin${moduleName}`;
129
+ const globalObject = getGlobalObject();
130
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
131
+ const plugin = globalObject[umdName];
132
+ if (!plugin) {
133
+ throw new Error(`Failed to load UMD bundle for ${moduleName}, ${globalObject.constructor.name}.${umdName} is undefined`);
134
+ }
135
+ return plugin;
136
+ }
137
+ async loadPlugin(definition) {
138
+ let plugin;
139
+ if (util_1.isElectron && isCJSPluginDefinition(definition)) {
140
+ plugin = await this.loadCJSPlugin(definition);
141
+ }
142
+ else if (isESMPluginDefinition(definition)) {
143
+ plugin = await this.loadESMPlugin(definition);
144
+ }
145
+ else if (isUMDPluginDefinition(definition)) {
146
+ plugin = await this.loadUMDPlugin(definition);
147
+ }
148
+ else if (!util_1.isElectron && isCJSPluginDefinition(definition)) {
149
+ throw new Error(`Only CommonJS plugin found, but not in a NodeJS environment: ${JSON.stringify(definition)}`);
150
+ }
151
+ else {
152
+ throw new Error(`Could not determine plugin type: ${JSON.stringify(definition)}`);
153
+ }
154
+ return plugin.default;
155
+ }
156
+ installGlobalReExports(target) {
157
+ // @ts-ignore
158
+ target.JBrowseExports = Object.fromEntries(Object.entries(ReExports_1.default).map(([moduleName, module]) => {
159
+ return [moduleName, module];
160
+ }));
161
+ }
162
+ async load() {
163
+ return Promise.all(this.definitions.map(async (definition) => ({
164
+ plugin: await this.loadPlugin(definition),
165
+ definition,
166
+ })));
167
+ }
168
+ }
169
+ exports.default = PluginLoader;