bruce-models 2.5.2 → 2.5.3

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.
@@ -11339,7 +11339,7 @@
11339
11339
  }
11340
11340
  Plugin.GetList = GetList;
11341
11341
  function GetLoadUrl(params) {
11342
- let { api, pluginId, req, cacheKey } = params;
11342
+ let { api, pluginId, cacheKey } = params;
11343
11343
  if (!api) {
11344
11344
  api = exports.ENVIRONMENT.Api().GetBruceApi();
11345
11345
  }
@@ -11351,6 +11351,87 @@
11351
11351
  };
11352
11352
  }
11353
11353
  Plugin.GetLoadUrl = GetLoadUrl;
11354
+ /**
11355
+ * Returns a run function to call that'll load a plugin within your provided container element.
11356
+ * The run function will return a dispose function to call to remove the plugin.
11357
+ * @param params
11358
+ * @returns
11359
+ */
11360
+ function GetRunFunction(params) {
11361
+ return __awaiter(this, void 0, void 0, function* () {
11362
+ let { containerId, container, pluginParams, pluginId, plugin, api } = params;
11363
+ if (!containerId && container) {
11364
+ containerId = container.id;
11365
+ if (!containerId) {
11366
+ containerId = exports.ObjectUtils.UId();
11367
+ container.id = containerId;
11368
+ }
11369
+ }
11370
+ if (!plugin && pluginId) {
11371
+ plugin = (yield Plugin.Get({
11372
+ pluginId,
11373
+ api
11374
+ })).plugin;
11375
+ }
11376
+ const { indexFileUrl } = GetLoadUrl({
11377
+ api,
11378
+ pluginId,
11379
+ cacheKey: plugin.Version
11380
+ });
11381
+ let fileContent = yield fetch(indexFileUrl).then((res) => res.text());
11382
+ const start = fileContent.indexOf("{");
11383
+ const end = fileContent.lastIndexOf("}");
11384
+ fileContent = fileContent.substring(start + 1, end);
11385
+ const paramsId = exports.ObjectUtils.UId();
11386
+ window[paramsId] = pluginParams ? pluginParams : {};
11387
+ const disposeId = exports.ObjectUtils.UId();
11388
+ let script = `
11389
+ function run() {
11390
+ ${fileContent}
11391
+
11392
+ const paramsId = "${paramsId}";
11393
+ const containerId = "${container.id}";
11394
+ let container;
11395
+ if (containerId) {
11396
+ container = document.getElementById("${container.id}");
11397
+ }
11398
+ {TEMPLATE_CODE}
11399
+ const params = window["${paramsId}"];
11400
+
11401
+ window["${disposeId}"] = Run({
11402
+ container,
11403
+ pluginParams: params
11404
+ });
11405
+ }
11406
+ run();
11407
+ `;
11408
+ if (script.includes("var template")) {
11409
+ script = script.replace("{TEMPLATE_CODE}", `
11410
+ if (container && template) {
11411
+ container.innerHTML = template;
11412
+ }
11413
+ `);
11414
+ }
11415
+ else {
11416
+ script = script.replace("{TEMPLATE_CODE}", "");
11417
+ }
11418
+ return {
11419
+ run: () => {
11420
+ const eval2 = eval;
11421
+ eval2(script);
11422
+ // Ensure a function is returned, even if the plugin is not configured properly to return one.
11423
+ if (!window[disposeId] || typeof window[disposeId] !== "function") {
11424
+ window[disposeId] = () => {
11425
+ console.warn("Plugin called to be disposed but no dispose function was found.");
11426
+ };
11427
+ }
11428
+ const callDispose = window[disposeId];
11429
+ return () => callDispose();
11430
+ }
11431
+ };
11432
+ });
11433
+ }
11434
+ Plugin.GetRunFunction = GetRunFunction;
11354
11435
  })(exports.Plugin || (exports.Plugin = {}));
11355
11436
 
11356
11437
  const VERSION$1 = "2.5.2";