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.
@@ -11573,7 +11573,7 @@ var Plugin;
11573
11573
  }
11574
11574
  Plugin.GetList = GetList;
11575
11575
  function GetLoadUrl(params) {
11576
- let { api, pluginId, req, cacheKey } = params;
11576
+ let { api, pluginId, cacheKey } = params;
11577
11577
  if (!api) {
11578
11578
  api = ENVIRONMENT.Api().GetBruceApi();
11579
11579
  }
@@ -11585,6 +11585,87 @@ var Plugin;
11585
11585
  };
11586
11586
  }
11587
11587
  Plugin.GetLoadUrl = GetLoadUrl;
11588
+ /**
11589
+ * Returns a run function to call that'll load a plugin within your provided container element.
11590
+ * The run function will return a dispose function to call to remove the plugin.
11591
+ * @param params
11592
+ * @returns
11593
+ */
11594
+ function GetRunFunction(params) {
11595
+ return __awaiter(this, void 0, void 0, function* () {
11596
+ let { containerId, container, pluginParams, pluginId, plugin, api } = params;
11597
+ if (!containerId && container) {
11598
+ containerId = container.id;
11599
+ if (!containerId) {
11600
+ containerId = ObjectUtils.UId();
11601
+ container.id = containerId;
11602
+ }
11603
+ }
11604
+ if (!plugin && pluginId) {
11605
+ plugin = (yield Plugin.Get({
11606
+ pluginId,
11607
+ api
11608
+ })).plugin;
11609
+ }
11610
+ const { indexFileUrl } = GetLoadUrl({
11611
+ api,
11612
+ pluginId,
11613
+ cacheKey: plugin.Version
11614
+ });
11615
+ let fileContent = yield fetch(indexFileUrl).then((res) => res.text());
11616
+ const start = fileContent.indexOf("{");
11617
+ const end = fileContent.lastIndexOf("}");
11618
+ fileContent = fileContent.substring(start + 1, end);
11619
+ const paramsId = ObjectUtils.UId();
11620
+ window[paramsId] = pluginParams ? pluginParams : {};
11621
+ const disposeId = ObjectUtils.UId();
11622
+ let script = `
11623
+ function run() {
11624
+ ${fileContent}
11625
+
11626
+ const paramsId = "${paramsId}";
11627
+ const containerId = "${container.id}";
11628
+ let container;
11629
+ if (containerId) {
11630
+ container = document.getElementById("${container.id}");
11631
+ }
11632
+ {TEMPLATE_CODE}
11633
+ const params = window["${paramsId}"];
11634
+
11635
+ window["${disposeId}"] = Run({
11636
+ container,
11637
+ pluginParams: params
11638
+ });
11639
+ }
11640
+ run();
11641
+ `;
11642
+ if (script.includes("var template")) {
11643
+ script = script.replace("{TEMPLATE_CODE}", `
11644
+ if (container && template) {
11645
+ container.innerHTML = template;
11646
+ }
11647
+ `);
11648
+ }
11649
+ else {
11650
+ script = script.replace("{TEMPLATE_CODE}", "");
11651
+ }
11652
+ return {
11653
+ run: () => {
11654
+ const eval2 = eval;
11655
+ eval2(script);
11656
+ // Ensure a function is returned, even if the plugin is not configured properly to return one.
11657
+ if (!window[disposeId] || typeof window[disposeId] !== "function") {
11658
+ window[disposeId] = () => {
11659
+ console.warn("Plugin called to be disposed but no dispose function was found.");
11660
+ };
11661
+ }
11662
+ const callDispose = window[disposeId];
11663
+ return () => callDispose();
11664
+ }
11665
+ };
11666
+ });
11667
+ }
11668
+ Plugin.GetRunFunction = GetRunFunction;
11588
11669
  })(Plugin || (Plugin = {}));
11589
11670
 
11590
11671
  const VERSION$1 = "2.5.2";