bruce-models 2.5.2 → 2.5.4
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.
- package/dist/bruce-models.es5.js +143 -1
- package/dist/bruce-models.es5.js.map +1 -1
- package/dist/bruce-models.umd.js +143 -1
- package/dist/bruce-models.umd.js.map +1 -1
- package/dist/lib/plugin/plugin.js +144 -1
- package/dist/lib/plugin/plugin.js.map +1 -1
- package/dist/types/plugin/plugin.d.ts +39 -1
- package/package.json +1 -1
package/dist/bruce-models.es5.js
CHANGED
|
@@ -11573,7 +11573,7 @@ var Plugin;
|
|
|
11573
11573
|
}
|
|
11574
11574
|
Plugin.GetList = GetList;
|
|
11575
11575
|
function GetLoadUrl(params) {
|
|
11576
|
-
let { api, pluginId,
|
|
11576
|
+
let { api, pluginId, cacheKey } = params;
|
|
11577
11577
|
if (!api) {
|
|
11578
11578
|
api = ENVIRONMENT.Api().GetBruceApi();
|
|
11579
11579
|
}
|
|
@@ -11585,6 +11585,148 @@ var Plugin;
|
|
|
11585
11585
|
};
|
|
11586
11586
|
}
|
|
11587
11587
|
Plugin.GetLoadUrl = GetLoadUrl;
|
|
11588
|
+
function Update(params) {
|
|
11589
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11590
|
+
let { plugin, api, req } = params;
|
|
11591
|
+
if (!api) {
|
|
11592
|
+
api = ENVIRONMENT.Api().GetBruceApi();
|
|
11593
|
+
}
|
|
11594
|
+
if (!plugin.Name || !plugin.ID) {
|
|
11595
|
+
throw ("Plugin name and ID are required.");
|
|
11596
|
+
}
|
|
11597
|
+
if (!plugin.ID) {
|
|
11598
|
+
plugin.ID = ObjectUtils.UId();
|
|
11599
|
+
}
|
|
11600
|
+
yield api.POST(`ui.plugin/${plugin.ID}`, plugin, Api.PrepReqParams(req));
|
|
11601
|
+
api.Cache.Remove(GetCacheKey(plugin.ID));
|
|
11602
|
+
api.Cache.Remove(GetListCacheKey());
|
|
11603
|
+
});
|
|
11604
|
+
}
|
|
11605
|
+
Plugin.Update = Update;
|
|
11606
|
+
function Delete(params) {
|
|
11607
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11608
|
+
let { pluginId, api, req } = params;
|
|
11609
|
+
if (!api) {
|
|
11610
|
+
api = ENVIRONMENT.Api().GetBruceApi();
|
|
11611
|
+
}
|
|
11612
|
+
if (!pluginId) {
|
|
11613
|
+
throw ("Plugin ID is required.");
|
|
11614
|
+
}
|
|
11615
|
+
yield api.DELETE(`ui.plugin/${pluginId}`, Api.PrepReqParams(req));
|
|
11616
|
+
api.Cache.Remove(GetCacheKey(pluginId));
|
|
11617
|
+
api.Cache.Remove(GetListCacheKey());
|
|
11618
|
+
});
|
|
11619
|
+
}
|
|
11620
|
+
Plugin.Delete = Delete;
|
|
11621
|
+
/**
|
|
11622
|
+
* Warning: This will replace the contents of your plugin.
|
|
11623
|
+
* Upload only ZIP files.
|
|
11624
|
+
* @param params
|
|
11625
|
+
*/
|
|
11626
|
+
function Upload(params) {
|
|
11627
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11628
|
+
let { pluginId, api, file, onProgress, req } = params;
|
|
11629
|
+
if (!api) {
|
|
11630
|
+
api = ENVIRONMENT.Api().GetBruceApi();
|
|
11631
|
+
}
|
|
11632
|
+
if (!pluginId || !file) {
|
|
11633
|
+
throw ("Plugin ID and file are required.");
|
|
11634
|
+
}
|
|
11635
|
+
req = Api.PrepReqParams(req);
|
|
11636
|
+
req.onProgress = (progress) => {
|
|
11637
|
+
const percent = Math.round((progress.loaded / file.size) * 100);
|
|
11638
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress({
|
|
11639
|
+
percent: percent,
|
|
11640
|
+
uploaded: false
|
|
11641
|
+
});
|
|
11642
|
+
};
|
|
11643
|
+
yield api.UPLOAD(`ui.plugin/${pluginId}/file`, file, req);
|
|
11644
|
+
api.Cache.Remove(GetCacheKey(pluginId));
|
|
11645
|
+
api.Cache.Remove(GetListCacheKey());
|
|
11646
|
+
});
|
|
11647
|
+
}
|
|
11648
|
+
Plugin.Upload = Upload;
|
|
11649
|
+
/**
|
|
11650
|
+
* Returns a run function to call that'll load a plugin within your provided container element.
|
|
11651
|
+
* The run function will return a dispose function to call to remove the plugin.
|
|
11652
|
+
* @param params
|
|
11653
|
+
* @returns
|
|
11654
|
+
*/
|
|
11655
|
+
function GetRunFunction(params) {
|
|
11656
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11657
|
+
let { containerId, container, pluginParams, pluginId, plugin, api } = params;
|
|
11658
|
+
if (!containerId && container) {
|
|
11659
|
+
containerId = container.id;
|
|
11660
|
+
if (!containerId) {
|
|
11661
|
+
containerId = ObjectUtils.UId();
|
|
11662
|
+
container.id = containerId;
|
|
11663
|
+
}
|
|
11664
|
+
}
|
|
11665
|
+
if (!plugin && pluginId) {
|
|
11666
|
+
plugin = (yield Plugin.Get({
|
|
11667
|
+
pluginId,
|
|
11668
|
+
api
|
|
11669
|
+
})).plugin;
|
|
11670
|
+
}
|
|
11671
|
+
const { indexFileUrl } = GetLoadUrl({
|
|
11672
|
+
api,
|
|
11673
|
+
pluginId,
|
|
11674
|
+
cacheKey: plugin.Version
|
|
11675
|
+
});
|
|
11676
|
+
let fileContent = yield fetch(indexFileUrl).then((res) => res.text());
|
|
11677
|
+
const start = fileContent.indexOf("{");
|
|
11678
|
+
const end = fileContent.lastIndexOf("}");
|
|
11679
|
+
fileContent = fileContent.substring(start + 1, end);
|
|
11680
|
+
const paramsId = ObjectUtils.UId();
|
|
11681
|
+
window[paramsId] = pluginParams ? pluginParams : {};
|
|
11682
|
+
const disposeId = ObjectUtils.UId();
|
|
11683
|
+
let script = `
|
|
11684
|
+
function run() {
|
|
11685
|
+
${fileContent}
|
|
11686
|
+
|
|
11687
|
+
const paramsId = "${paramsId}";
|
|
11688
|
+
const containerId = "${container.id}";
|
|
11689
|
+
let container;
|
|
11690
|
+
if (containerId) {
|
|
11691
|
+
container = document.getElementById("${container.id}");
|
|
11692
|
+
}
|
|
11693
|
+
{TEMPLATE_CODE}
|
|
11694
|
+
const params = window["${paramsId}"];
|
|
11695
|
+
|
|
11696
|
+
window["${disposeId}"] = Run({
|
|
11697
|
+
container,
|
|
11698
|
+
pluginParams: params
|
|
11699
|
+
});
|
|
11700
|
+
}
|
|
11701
|
+
run();
|
|
11702
|
+
`;
|
|
11703
|
+
if (script.includes("var template")) {
|
|
11704
|
+
script = script.replace("{TEMPLATE_CODE}", `
|
|
11705
|
+
if (container && template) {
|
|
11706
|
+
container.innerHTML = template;
|
|
11707
|
+
}
|
|
11708
|
+
`);
|
|
11709
|
+
}
|
|
11710
|
+
else {
|
|
11711
|
+
script = script.replace("{TEMPLATE_CODE}", "");
|
|
11712
|
+
}
|
|
11713
|
+
return {
|
|
11714
|
+
run: () => {
|
|
11715
|
+
const eval2 = eval;
|
|
11716
|
+
eval2(script);
|
|
11717
|
+
// Ensure a function is returned, even if the plugin is not configured properly to return one.
|
|
11718
|
+
if (!window[disposeId] || typeof window[disposeId] !== "function") {
|
|
11719
|
+
window[disposeId] = () => {
|
|
11720
|
+
console.warn("Plugin called to be disposed but no dispose function was found.");
|
|
11721
|
+
};
|
|
11722
|
+
}
|
|
11723
|
+
const callDispose = window[disposeId];
|
|
11724
|
+
return () => callDispose();
|
|
11725
|
+
}
|
|
11726
|
+
};
|
|
11727
|
+
});
|
|
11728
|
+
}
|
|
11729
|
+
Plugin.GetRunFunction = GetRunFunction;
|
|
11588
11730
|
})(Plugin || (Plugin = {}));
|
|
11589
11731
|
|
|
11590
11732
|
const VERSION$1 = "2.5.2";
|