bruce-models 2.5.1 → 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.
@@ -3117,45 +3117,24 @@ class CacheControl {
3117
3117
  // Need to see if our api is generally good at setting content-type headers.
3118
3118
  // Make it less specific to CSV.
3119
3119
  function parseResult(data) {
3120
+ var _a, _b;
3120
3121
  return __awaiter(this, void 0, void 0, function* () {
3121
- if (data.status == 200) {
3122
- let type = data.headers.get("Content-Type");
3123
- if (type) {
3124
- type = type.trim().toLowerCase();
3125
- }
3126
- let encoding = "";
3127
- const charset = type ? type.split(";").find((x) => x.startsWith("charset=")) : "";
3128
- if (charset && charset.includes("=")) {
3129
- encoding = charset.split("=")[1];
3130
- encoding = encoding.toLowerCase();
3131
- }
3132
- // Our API has a very specific utf-16 encoding.
3133
- if (encoding == "utf-16") {
3134
- encoding = Api.EEncoding.UTF16;
3135
- }
3136
- if (!encoding || encoding == "utf-8") {
3137
- const text = yield data.text();
3138
- if (!text || !text.trim()) {
3139
- return null;
3140
- }
3141
- if (type && type.includes("text/csv")) {
3142
- return text;
3143
- }
3144
- return JSON.parse(text);
3145
- }
3146
- else {
3147
- const buffer = yield data.arrayBuffer();
3148
- const text = new TextDecoder(encoding).decode(buffer);
3149
- if (type && type.includes("text/csv")) {
3150
- return text;
3151
- }
3152
- return JSON.parse(text);
3153
- }
3154
- }
3155
- else {
3122
+ if (data.status !== 200) {
3156
3123
  const error = yield data.json();
3157
3124
  throw (error);
3158
3125
  }
3126
+ let type = (_a = data.headers.get("Content-Type")) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase();
3127
+ let encoding = (_b = type === null || type === void 0 ? void 0 : type.split(";").find((x) => x.startsWith("charset="))) === null || _b === void 0 ? void 0 : _b.split("=")[1].toLowerCase();
3128
+ if (encoding === "utf-16") {
3129
+ encoding = Api.EEncoding.UTF16;
3130
+ }
3131
+ const text = yield (encoding && encoding !== "utf-8"
3132
+ ? new TextDecoder(encoding).decode(yield data.arrayBuffer())
3133
+ : data.text());
3134
+ if (!(text === null || text === void 0 ? void 0 : text.trim())) {
3135
+ return null;
3136
+ }
3137
+ return (type === null || type === void 0 ? void 0 : type.includes("text/csv")) ? text : JSON.parse(text);
3159
3138
  });
3160
3139
  }
3161
3140
  /**
@@ -11594,7 +11573,7 @@ var Plugin;
11594
11573
  }
11595
11574
  Plugin.GetList = GetList;
11596
11575
  function GetLoadUrl(params) {
11597
- let { api, pluginId, req, cacheKey } = params;
11576
+ let { api, pluginId, cacheKey } = params;
11598
11577
  if (!api) {
11599
11578
  api = ENVIRONMENT.Api().GetBruceApi();
11600
11579
  }
@@ -11606,7 +11585,90 @@ var Plugin;
11606
11585
  };
11607
11586
  }
11608
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;
11609
11669
  })(Plugin || (Plugin = {}));
11610
11670
 
11611
- export { AnnDocument, CustomForm, CustomFormContent, AbstractApi, Api, BruceApi, CamApi, IdmApi, GlobalApi, GuardianApi, ApiGetters, Calculator, Bounds, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, BruceVariable, LRUCache, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityLodCategory, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityGlobe, EntityFilterGetter, BatchedDataGetter, EntityCoords, EntityTypeVisualSettings, EntityAttribute, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, PendingAction, MessageBroker, HostingLocation, Style, Tileset, Permission, Session, UserGroup, User, Account, AccountInvite, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile, Markup, Uploader, Plugin, ENVIRONMENT };
11671
+ const VERSION$1 = "2.5.2";
11672
+
11673
+ export { VERSION$1 as VERSION, AnnDocument, CustomForm, CustomFormContent, AbstractApi, Api, BruceApi, CamApi, IdmApi, GlobalApi, GuardianApi, ApiGetters, Calculator, Bounds, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, BruceVariable, LRUCache, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityLodCategory, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityGlobe, EntityFilterGetter, BatchedDataGetter, EntityCoords, EntityTypeVisualSettings, EntityAttribute, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, ProjectViewLegacyTile, ProjectViewTile, PendingAction, MessageBroker, HostingLocation, Style, Tileset, Permission, Session, UserGroup, User, Account, AccountInvite, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils, DataLab, ImportCad, ImportCsv, ImportJson, ImportKml, ImportedFile, Markup, Uploader, Plugin, ENVIRONMENT };
11612
11674
  //# sourceMappingURL=bruce-models.es5.js.map