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.umd.js
CHANGED
|
@@ -11339,7 +11339,7 @@
|
|
|
11339
11339
|
}
|
|
11340
11340
|
Plugin.GetList = GetList;
|
|
11341
11341
|
function GetLoadUrl(params) {
|
|
11342
|
-
let { api, pluginId,
|
|
11342
|
+
let { api, pluginId, cacheKey } = params;
|
|
11343
11343
|
if (!api) {
|
|
11344
11344
|
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
11345
11345
|
}
|
|
@@ -11351,6 +11351,148 @@
|
|
|
11351
11351
|
};
|
|
11352
11352
|
}
|
|
11353
11353
|
Plugin.GetLoadUrl = GetLoadUrl;
|
|
11354
|
+
function Update(params) {
|
|
11355
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11356
|
+
let { plugin, api, req } = params;
|
|
11357
|
+
if (!api) {
|
|
11358
|
+
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
11359
|
+
}
|
|
11360
|
+
if (!plugin.Name || !plugin.ID) {
|
|
11361
|
+
throw ("Plugin name and ID are required.");
|
|
11362
|
+
}
|
|
11363
|
+
if (!plugin.ID) {
|
|
11364
|
+
plugin.ID = exports.ObjectUtils.UId();
|
|
11365
|
+
}
|
|
11366
|
+
yield api.POST(`ui.plugin/${plugin.ID}`, plugin, exports.Api.PrepReqParams(req));
|
|
11367
|
+
api.Cache.Remove(GetCacheKey(plugin.ID));
|
|
11368
|
+
api.Cache.Remove(GetListCacheKey());
|
|
11369
|
+
});
|
|
11370
|
+
}
|
|
11371
|
+
Plugin.Update = Update;
|
|
11372
|
+
function Delete(params) {
|
|
11373
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11374
|
+
let { pluginId, api, req } = params;
|
|
11375
|
+
if (!api) {
|
|
11376
|
+
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
11377
|
+
}
|
|
11378
|
+
if (!pluginId) {
|
|
11379
|
+
throw ("Plugin ID is required.");
|
|
11380
|
+
}
|
|
11381
|
+
yield api.DELETE(`ui.plugin/${pluginId}`, exports.Api.PrepReqParams(req));
|
|
11382
|
+
api.Cache.Remove(GetCacheKey(pluginId));
|
|
11383
|
+
api.Cache.Remove(GetListCacheKey());
|
|
11384
|
+
});
|
|
11385
|
+
}
|
|
11386
|
+
Plugin.Delete = Delete;
|
|
11387
|
+
/**
|
|
11388
|
+
* Warning: This will replace the contents of your plugin.
|
|
11389
|
+
* Upload only ZIP files.
|
|
11390
|
+
* @param params
|
|
11391
|
+
*/
|
|
11392
|
+
function Upload(params) {
|
|
11393
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11394
|
+
let { pluginId, api, file, onProgress, req } = params;
|
|
11395
|
+
if (!api) {
|
|
11396
|
+
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
11397
|
+
}
|
|
11398
|
+
if (!pluginId || !file) {
|
|
11399
|
+
throw ("Plugin ID and file are required.");
|
|
11400
|
+
}
|
|
11401
|
+
req = exports.Api.PrepReqParams(req);
|
|
11402
|
+
req.onProgress = (progress) => {
|
|
11403
|
+
const percent = Math.round((progress.loaded / file.size) * 100);
|
|
11404
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress({
|
|
11405
|
+
percent: percent,
|
|
11406
|
+
uploaded: false
|
|
11407
|
+
});
|
|
11408
|
+
};
|
|
11409
|
+
yield api.UPLOAD(`ui.plugin/${pluginId}/file`, file, req);
|
|
11410
|
+
api.Cache.Remove(GetCacheKey(pluginId));
|
|
11411
|
+
api.Cache.Remove(GetListCacheKey());
|
|
11412
|
+
});
|
|
11413
|
+
}
|
|
11414
|
+
Plugin.Upload = Upload;
|
|
11415
|
+
/**
|
|
11416
|
+
* Returns a run function to call that'll load a plugin within your provided container element.
|
|
11417
|
+
* The run function will return a dispose function to call to remove the plugin.
|
|
11418
|
+
* @param params
|
|
11419
|
+
* @returns
|
|
11420
|
+
*/
|
|
11421
|
+
function GetRunFunction(params) {
|
|
11422
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
11423
|
+
let { containerId, container, pluginParams, pluginId, plugin, api } = params;
|
|
11424
|
+
if (!containerId && container) {
|
|
11425
|
+
containerId = container.id;
|
|
11426
|
+
if (!containerId) {
|
|
11427
|
+
containerId = exports.ObjectUtils.UId();
|
|
11428
|
+
container.id = containerId;
|
|
11429
|
+
}
|
|
11430
|
+
}
|
|
11431
|
+
if (!plugin && pluginId) {
|
|
11432
|
+
plugin = (yield Plugin.Get({
|
|
11433
|
+
pluginId,
|
|
11434
|
+
api
|
|
11435
|
+
})).plugin;
|
|
11436
|
+
}
|
|
11437
|
+
const { indexFileUrl } = GetLoadUrl({
|
|
11438
|
+
api,
|
|
11439
|
+
pluginId,
|
|
11440
|
+
cacheKey: plugin.Version
|
|
11441
|
+
});
|
|
11442
|
+
let fileContent = yield fetch(indexFileUrl).then((res) => res.text());
|
|
11443
|
+
const start = fileContent.indexOf("{");
|
|
11444
|
+
const end = fileContent.lastIndexOf("}");
|
|
11445
|
+
fileContent = fileContent.substring(start + 1, end);
|
|
11446
|
+
const paramsId = exports.ObjectUtils.UId();
|
|
11447
|
+
window[paramsId] = pluginParams ? pluginParams : {};
|
|
11448
|
+
const disposeId = exports.ObjectUtils.UId();
|
|
11449
|
+
let script = `
|
|
11450
|
+
function run() {
|
|
11451
|
+
${fileContent}
|
|
11452
|
+
|
|
11453
|
+
const paramsId = "${paramsId}";
|
|
11454
|
+
const containerId = "${container.id}";
|
|
11455
|
+
let container;
|
|
11456
|
+
if (containerId) {
|
|
11457
|
+
container = document.getElementById("${container.id}");
|
|
11458
|
+
}
|
|
11459
|
+
{TEMPLATE_CODE}
|
|
11460
|
+
const params = window["${paramsId}"];
|
|
11461
|
+
|
|
11462
|
+
window["${disposeId}"] = Run({
|
|
11463
|
+
container,
|
|
11464
|
+
pluginParams: params
|
|
11465
|
+
});
|
|
11466
|
+
}
|
|
11467
|
+
run();
|
|
11468
|
+
`;
|
|
11469
|
+
if (script.includes("var template")) {
|
|
11470
|
+
script = script.replace("{TEMPLATE_CODE}", `
|
|
11471
|
+
if (container && template) {
|
|
11472
|
+
container.innerHTML = template;
|
|
11473
|
+
}
|
|
11474
|
+
`);
|
|
11475
|
+
}
|
|
11476
|
+
else {
|
|
11477
|
+
script = script.replace("{TEMPLATE_CODE}", "");
|
|
11478
|
+
}
|
|
11479
|
+
return {
|
|
11480
|
+
run: () => {
|
|
11481
|
+
const eval2 = eval;
|
|
11482
|
+
eval2(script);
|
|
11483
|
+
// Ensure a function is returned, even if the plugin is not configured properly to return one.
|
|
11484
|
+
if (!window[disposeId] || typeof window[disposeId] !== "function") {
|
|
11485
|
+
window[disposeId] = () => {
|
|
11486
|
+
console.warn("Plugin called to be disposed but no dispose function was found.");
|
|
11487
|
+
};
|
|
11488
|
+
}
|
|
11489
|
+
const callDispose = window[disposeId];
|
|
11490
|
+
return () => callDispose();
|
|
11491
|
+
}
|
|
11492
|
+
};
|
|
11493
|
+
});
|
|
11494
|
+
}
|
|
11495
|
+
Plugin.GetRunFunction = GetRunFunction;
|
|
11354
11496
|
})(exports.Plugin || (exports.Plugin = {}));
|
|
11355
11497
|
|
|
11356
11498
|
const VERSION$1 = "2.5.2";
|