@splunk/visualizations-shared 27.5.0 → 28.1.0

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/.eslintrc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "rules": {
3
+ "import/no-extraneous-dependencies": "off"
4
+ }
5
+ }
@@ -0,0 +1,64 @@
1
+ /* Copyright © 2020 Splunk Inc.
2
+ SPLUNK CONFIDENTIAL – Use or disclosure of this material in whole or
3
+ in part without a valid written license from Splunk Inc. is PROHIBITED. */
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // src/AsyncStoryDecorator.jsx
34
+ var AsyncStoryDecorator_exports = {};
35
+ __export(AsyncStoryDecorator_exports, {
36
+ AsyncStoryDecorator: () => AsyncStoryDecorator
37
+ });
38
+ module.exports = __toCommonJS(AsyncStoryDecorator_exports);
39
+
40
+ // esm-externals:react
41
+ var react_exports = {};
42
+ __export(react_exports, {
43
+ default: () => react_default
44
+ });
45
+ var defaultImport = __toESM(require("react"));
46
+ __reExport(react_exports, require("react"));
47
+ var react_default = "default" in defaultImport ? defaultImport.default : defaultImport;
48
+
49
+ // esm-externals:@loki/create-async-callback
50
+ var create_async_callback_exports = {};
51
+ __export(create_async_callback_exports, {
52
+ default: () => create_async_callback_default
53
+ });
54
+ var defaultImport2 = __toESM(require("@loki/create-async-callback"));
55
+ __reExport(create_async_callback_exports, require("@loki/create-async-callback"));
56
+ var create_async_callback_default = "default" in defaultImport2 ? defaultImport2.default : defaultImport2;
57
+
58
+ // src/AsyncStoryDecorator.jsx
59
+ var AsyncStoryDecorator = (Story) => {
60
+ const asyncCallback = create_async_callback_default();
61
+ setTimeout(asyncCallback, 3e3);
62
+ return /* @__PURE__ */ react_exports.createElement(Story, null);
63
+ };
64
+ //# sourceMappingURL=AsyncStoryDecorator.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/AsyncStoryDecorator.jsx", "esm-externals:react", "esm-externals:@loki/create-async-callback"],
4
+ "sourcesContent": ["// eslint-disable-next-line no-use-before-define\nimport * as React from 'react';\nimport createAsyncCallback from '@loki/create-async-callback';\n\nexport const AsyncStoryDecorator = Story => {\n const asyncCallback = createAsyncCallback();\n setTimeout(asyncCallback, 3000);\n return <Story />;\n};\n", "\nimport * as defaultImport from \"react\";\nexport * from \"react\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"@loki/create-async-callback\";\nexport * from \"@loki/create-async-callback\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AACA,oBAA+B;AAC/B,0BAAc;AACd,IAAO,gBAAS,aAAa,gBAA8B,wBAAU;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAA,iBAA+B;AAC/B,0CAAc;AACd,IAAO,gCAAS,aAAaA,iBAA8B,yBAAUA;;;AFC9D,IAAM,sBAAsB,WAAS;AACxC,QAAM,gBAAgB,8BAAoB;AAC1C,aAAW,eAAe,GAAI;AAC9B,SAAO,4CAAC,WAAM;AAClB;",
6
+ "names": ["defaultImport"]
7
+ }
package/Downloader.js CHANGED
@@ -103,49 +103,50 @@ var ImageRegistryFetcher = class {
103
103
  };
104
104
  var URLDownloader = class {
105
105
  downloadWithProgress(url, complete, progress, error) {
106
- fetch(url).then(
107
- (response) => __async(this, null, function* () {
108
- if (!response.ok) {
109
- const msg = `Fetch not Ok for ${url}, status was '${response.statusText}'`;
110
- console.warn(msg);
111
- error(msg);
106
+ fetch(url).then((response) => __async(this, null, function* () {
107
+ if (!response.ok) {
108
+ const msg = `Fetch not Ok for ${url}, status was '${response.statusText}'`;
109
+ console.warn(msg);
110
+ error(msg);
111
+ return;
112
+ }
113
+ const reader = response.body.getReader();
114
+ const contentLength = +response.headers.get("Content-Length");
115
+ let bytesDownloaded = 0;
116
+ const chunks = [];
117
+ let done = false;
118
+ while (!done) {
119
+ const res = yield reader.read();
120
+ if (!res) {
112
121
  return;
113
122
  }
114
- const reader = response.body.getReader();
115
- const contentLength = +response.headers.get("Content-Length");
116
- let bytesDownloaded = 0;
117
- const chunks = [];
118
- let done = false;
119
- while (!done) {
120
- const res = yield reader.read();
121
- done = res.done;
122
- const { value } = res;
123
- if (value) {
124
- chunks.push(value);
125
- bytesDownloaded += value.length;
126
- progress({
127
- // call the progress callback...can enable the UI to show progress
128
- bytesDownloaded,
129
- contentLength,
130
- message: `Received ${bytesDownloaded} bytes of ${contentLength || "unknown size"}`
131
- });
132
- }
133
- }
134
- const chunksAll = new Uint8Array(bytesDownloaded);
135
- let position = 0;
136
- for (const chunk of chunks) {
137
- chunksAll.set(chunk, position);
138
- position += chunk.length;
123
+ done = res.done;
124
+ const { value } = res;
125
+ if (value) {
126
+ chunks.push(value);
127
+ bytesDownloaded += value.length;
128
+ progress({
129
+ // call the progress callback...can enable the UI to show progress
130
+ bytesDownloaded,
131
+ contentLength,
132
+ message: `Received ${bytesDownloaded} bytes of ${contentLength || "unknown size"}`
133
+ });
139
134
  }
140
- progress({
141
- bytesDownloaded,
142
- contentLength,
143
- message: "decoding chunks"
144
- });
145
- const svg = new TextDecoder("utf-8").decode(chunksAll);
146
- complete(svg);
147
- })
148
- ).catch((e) => {
135
+ }
136
+ const chunksAll = new Uint8Array(bytesDownloaded);
137
+ let position = 0;
138
+ for (const chunk of chunks) {
139
+ chunksAll.set(chunk, position);
140
+ position += chunk.length;
141
+ }
142
+ progress({
143
+ bytesDownloaded,
144
+ contentLength,
145
+ message: "decoding chunks"
146
+ });
147
+ const svg = new TextDecoder("utf-8").decode(chunksAll);
148
+ complete(svg);
149
+ })).catch((e) => {
149
150
  const stringifiedError = e.toString();
150
151
  console.error(stringifiedError);
151
152
  if (stringifiedError.includes("Failed to fetch")) {
package/Downloader.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/Downloader.ts", "esm-externals:@splunk/ui-utils/i18n"],
4
- "sourcesContent": ["/* eslint-disable max-classes-per-file */\n/* eslint-disable class-methods-use-this */\nimport { _ } from '@splunk/ui-utils/i18n';\nimport ImageRegistry from '@splunk/visualization-context/ImageRegistry';\n\nexport interface DownloadProgress {\n bytesDownloaded: number;\n contentLength?: number;\n message: string;\n}\nexport interface IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void;\n}\n\nexport const b64DecodeUnicode = (base64Data: string): string => {\n // from bytestream, to percent-encoding, to original string.\n return decodeURIComponent(\n atob(base64Data)\n .split('')\n .map((c: string): string => {\n return `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`;\n })\n .join('')\n );\n};\n\nexport class ImageRegistryFetcher implements IDownloader {\n context: ImageRegistry;\n\n constructor(context?: ImageRegistry) {\n this.context = context;\n }\n\n async downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): Promise<void> {\n const imageRegistry = this.context;\n if (!imageRegistry) {\n error(_('Missing Image Context'));\n }\n try {\n const imageData = await imageRegistry.getByURL(url);\n const [mime, svgBase64] = imageData.dataURI.split('base64,');\n if (mime && mime.toLowerCase().indexOf('image/svg+xml') > -1) {\n complete(b64DecodeUnicode(svgBase64));\n } else {\n error(_(`Unsupported MIME type ${mime} for url ${url}`));\n }\n } catch (e) {\n error(_(`Error retrieving ${url} from Image Registry, error was '${e.message}'`), e);\n }\n }\n}\n\nexport class URLDownloader implements IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // Step 1: fetch content from URL, get reader\n fetch(url)\n .then(\n async (response: Response): Promise<void> => {\n if (!response.ok) {\n const msg = `Fetch not Ok for ${url}, status was '${response.statusText}'`;\n console.warn(msg);\n error(msg);\n return;\n }\n const reader = response.body.getReader();\n\n // Step 2: get total length\n const contentLength = +response.headers.get('Content-Length');\n\n // Step 3: read the data\n let bytesDownloaded = 0; // length at the moment\n const chunks = []; // array of received binary chunks (comprises the body)\n let done = false;\n while (!done) {\n // eslint-disable-next-line no-await-in-loop\n const res = await reader.read();\n done = res.done;\n const { value } = res;\n if (value) {\n chunks.push(value);\n bytesDownloaded += value.length;\n progress({\n // call the progress callback...can enable the UI to show progress\n bytesDownloaded,\n contentLength,\n message: `Received ${bytesDownloaded} bytes of ${\n contentLength || 'unknown size'\n }`,\n });\n }\n }\n\n // Step 4: concatenate chunks into single Uint8Array\n const chunksAll = new Uint8Array(bytesDownloaded);\n let position = 0;\n // eslint-disable-next-line no-restricted-syntax\n for (const chunk of chunks) {\n chunksAll.set(chunk, position);\n position += chunk.length;\n }\n\n progress({\n bytesDownloaded,\n contentLength,\n message: 'decoding chunks',\n });\n\n // Step 5: decode into a string\n const svg = new TextDecoder('utf-8').decode(chunksAll);\n complete(svg); // show the downloaded svg back to the caller via its completion callback\n }\n )\n .catch((e: Error): void => {\n // Note: For CORS issue, fetch api call immediately fails without any status code or response and the error message says \"Failed to fetch\"\n // but for other issues (invalid url, not found, etc), it returns with a certain status code (406, 404, etc)\n // and empty response so further operation on the response data fails.\n const stringifiedError = e.toString();\n console.error(stringifiedError);\n // call the supplied error handling function\n if (stringifiedError.includes('Failed to fetch')) {\n error(\n `Cannot fetch the image \"${url}\" due to a cross-origin resource sharing (CORS) policy`,\n e\n );\n } else {\n error(`Fetch error for '${url}', error was '${e.toString()}'`, e);\n }\n });\n }\n}\n\nexport default class Downloader {\n private downloaders = {};\n\n constructor(downloaders: { [protocol: string]: IDownloader }) {\n this.downloaders = downloaders;\n }\n\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // url is the following:\n // data:image/svg+xml;base64....\n // http://\n // https://\n // local://\n // or otherwise return errors\n\n let protocol = '';\n let isUrl = true;\n try {\n protocol = new URL(url).protocol;\n } catch (e) {\n isUrl = false;\n }\n\n if (isUrl) {\n try {\n const [type = ''] = protocol.split(':');\n if (this.downloaders[type]) {\n // data, http(s), local....\n this.downloaders[type].downloadWithProgress(url, complete, progress, error);\n } else {\n // unknown type\n error(`Unsupported URL protocol '${type}' for SVG download: ${url}`);\n }\n } catch (e) {\n error(`Unexpected error downloading SVG: ${e.message}`);\n }\n } else {\n // the url might be literal content. <svg>...</svg>. This is kindof a hack where if you pass the downloader something\n // that is literal content, it will just return the content. Makes the code flow cleaner in layers above.\n complete(url);\n }\n }\n}\n", "\nimport * as defaultImport from \"@splunk/ui-utils/i18n\";\nexport * from \"@splunk/ui-utils/i18n\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AACA,oBAA+B;AAC/B,yBAAc;AACd,IAAO,eAAS,aAAa,gBAA8B,wBAAU;;;ADgB9D,IAAM,mBAAmB,CAAC,eAA+B;AAE5D,SAAO;AAAA,IACH,KAAK,UAAU,EACV,MAAM,EAAE,EACR,IAAI,CAAC,MAAsB;AACxB,aAAO,IAAI,KAAK,EAAE,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC;AAAA,IAC5D,CAAC,EACA,KAAK,EAAE;AAAA,EAChB;AACJ;AAEO,IAAM,uBAAN,MAAkD;AAAA,EAGrD,YAAY,SAAyB;AACjC,SAAK,UAAU;AAAA,EACnB;AAAA,EAEM,qBACF,KACA,UACA,UACA,OACa;AAAA;AACb,YAAM,gBAAgB,KAAK;AAC3B,UAAI,CAAC,eAAe;AAChB,kBAAM,gBAAE,uBAAuB,CAAC;AAAA,MACpC;AACA,UAAI;AACA,cAAM,YAAY,MAAM,cAAc,SAAS,GAAG;AAClD,cAAM,CAAC,MAAM,SAAS,IAAI,UAAU,QAAQ,MAAM,SAAS;AAC3D,YAAI,QAAQ,KAAK,YAAY,EAAE,QAAQ,eAAe,IAAI,IAAI;AAC1D,mBAAS,iBAAiB,SAAS,CAAC;AAAA,QACxC,OAAO;AACH,oBAAM,gBAAE,yBAAyB,IAAI,YAAY,GAAG,EAAE,CAAC;AAAA,QAC3D;AAAA,MACJ,SAAS,GAAG;AACR,kBAAM,gBAAE,oBAAoB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B,GAAG;AAC9C;AAAA,UACI,2BAA2B,GAAG;AAAA,UAC9B;AAAA,QACJ;AAAA,MACJ,OAAO;AACH,cAAM,oBAAoB,GAAG,iBAAiB,EAAE,SAAS,CAAC,KAAK,CAAC;AAAA,MACpE;AAAA,IACJ,CAAC;AAAA,EACT;AACJ;AAEA,IAAqB,aAArB,MAAgC;AAAA,EAG5B,YAAY,aAAkD;AAF9D,SAAQ,cAAc,CAAC;AAGnB,SAAK,cAAc;AAAA,EACvB;AAAA,EAEA,qBACI,KACA,UACA,UACA,OACI;AAQJ,QAAI,WAAW;AACf,QAAI,QAAQ;AACZ,QAAI;AACA,iBAAW,IAAI,IAAI,GAAG,EAAE;AAAA,IAC5B,SAAS,GAAG;AACR,cAAQ;AAAA,IACZ;AAEA,QAAI,OAAO;AACP,UAAI;AACA,cAAM,CAAC,OAAO,EAAE,IAAI,SAAS,MAAM,GAAG;AACtC,YAAI,KAAK,YAAY,IAAI,GAAG;AAExB,eAAK,YAAY,IAAI,EAAE,qBAAqB,KAAK,UAAU,UAAU,KAAK;AAAA,QAC9E,OAAO;AAEH,gBAAM,6BAA6B,IAAI,uBAAuB,GAAG,EAAE;AAAA,QACvE;AAAA,MACJ,SAAS,GAAG;AACR,cAAM,qCAAqC,EAAE,OAAO,EAAE;AAAA,MAC1D;AAAA,IACJ,OAAO;AAGH,eAAS,GAAG;AAAA,IAChB;AAAA,EACJ;AACJ;",
4
+ "sourcesContent": ["/* eslint-disable max-classes-per-file */\n/* eslint-disable class-methods-use-this */\nimport { _ } from '@splunk/ui-utils/i18n';\nimport ImageRegistry from '@splunk/visualization-context/ImageRegistry';\n\nexport interface DownloadProgress {\n bytesDownloaded: number;\n contentLength?: number;\n message: string;\n}\nexport interface IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void;\n}\n\nexport const b64DecodeUnicode = (base64Data: string): string => {\n // from bytestream, to percent-encoding, to original string.\n return decodeURIComponent(\n atob(base64Data)\n .split('')\n .map((c: string): string => {\n return `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`;\n })\n .join('')\n );\n};\n\nexport class ImageRegistryFetcher implements IDownloader {\n context: ImageRegistry;\n\n constructor(context?: ImageRegistry) {\n this.context = context;\n }\n\n async downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): Promise<void> {\n const imageRegistry = this.context;\n if (!imageRegistry) {\n error(_('Missing Image Context'));\n }\n try {\n const imageData = await imageRegistry.getByURL(url);\n const [mime, svgBase64] = imageData.dataURI.split('base64,');\n if (mime && mime.toLowerCase().indexOf('image/svg+xml') > -1) {\n complete(b64DecodeUnicode(svgBase64));\n } else {\n error(_(`Unsupported MIME type ${mime} for url ${url}`));\n }\n } catch (e) {\n error(_(`Error retrieving ${url} from Image Registry, error was '${e.message}'`), e);\n }\n }\n}\n\nexport class URLDownloader implements IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // Step 1: fetch content from URL, get reader\n fetch(url)\n .then(async (response: Response): Promise<void> => {\n if (!response.ok) {\n const msg = `Fetch not Ok for ${url}, status was '${response.statusText}'`;\n // eslint-disable-next-line no-console\n console.warn(msg);\n error(msg);\n return;\n }\n const reader = response.body.getReader();\n\n // Step 2: get total length\n const contentLength = +response.headers.get('Content-Length');\n\n // Step 3: read the data\n let bytesDownloaded = 0; // length at the moment\n const chunks = []; // array of received binary chunks (comprises the body)\n let done = false;\n while (!done) {\n // eslint-disable-next-line no-await-in-loop\n const res = await reader.read();\n if (!res) {\n return;\n }\n done = res.done;\n const { value } = res;\n if (value) {\n chunks.push(value);\n bytesDownloaded += value.length;\n progress({\n // call the progress callback...can enable the UI to show progress\n bytesDownloaded,\n contentLength,\n message: `Received ${bytesDownloaded} bytes of ${\n contentLength || 'unknown size'\n }`,\n });\n }\n }\n\n // Step 4: concatenate chunks into single Uint8Array\n const chunksAll = new Uint8Array(bytesDownloaded);\n let position = 0;\n // eslint-disable-next-line no-restricted-syntax\n for (const chunk of chunks) {\n chunksAll.set(chunk, position);\n position += chunk.length;\n }\n\n progress({\n bytesDownloaded,\n contentLength,\n message: 'decoding chunks',\n });\n\n // Step 5: decode into a string\n const svg = new TextDecoder('utf-8').decode(chunksAll);\n complete(svg); // show the downloaded svg back to the caller via its completion callback\n })\n .catch((e: Error): void => {\n // Note: For CORS issue, fetch api call immediately fails without any status code or response and the error message says \"Failed to fetch\"\n // but for other issues (invalid url, not found, etc), it returns with a certain status code (406, 404, etc)\n // and empty response so further operation on the response data fails.\n const stringifiedError = e.toString();\n // eslint-disable-next-line no-console\n console.error(stringifiedError);\n // call the supplied error handling function\n if (stringifiedError.includes('Failed to fetch')) {\n error(\n `Cannot fetch the image \"${url}\" due to a cross-origin resource sharing (CORS) policy`,\n e\n );\n } else {\n error(`Fetch error for '${url}', error was '${e.toString()}'`, e);\n }\n });\n }\n}\n\nexport default class Downloader {\n private downloaders = {};\n\n constructor(downloaders: { [protocol: string]: IDownloader }) {\n this.downloaders = downloaders;\n }\n\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // url is the following:\n // data:image/svg+xml;base64....\n // http://\n // https://\n // local://\n // or otherwise return errors\n\n let protocol = '';\n let isUrl = true;\n try {\n protocol = new URL(url).protocol;\n } catch (e) {\n isUrl = false;\n }\n\n if (isUrl) {\n try {\n const [type = ''] = protocol.split(':');\n if (this.downloaders[type]) {\n // data, http(s), local....\n this.downloaders[type].downloadWithProgress(url, complete, progress, error);\n } else {\n // unknown type\n error(`Unsupported URL protocol '${type}' for SVG download: ${url}`);\n }\n } catch (e) {\n error(`Unexpected error downloading SVG: ${e.message}`);\n }\n } else {\n // the url might be literal content. <svg>...</svg>. This is kindof a hack where if you pass the downloader something\n // that is literal content, it will just return the content. Makes the code flow cleaner in layers above.\n complete(url);\n }\n }\n}\n", "\nimport * as defaultImport from \"@splunk/ui-utils/i18n\";\nexport * from \"@splunk/ui-utils/i18n\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AACA,oBAA+B;AAC/B,yBAAc;AACd,IAAO,eAAS,aAAa,gBAA8B,wBAAU;;;ADgB9D,IAAM,mBAAmB,CAAC,eAA+B;AAE5D,SAAO;AAAA,IACH,KAAK,UAAU,EACV,MAAM,EAAE,EACR,IAAI,CAAC,MAAsB;AACxB,aAAO,IAAI,KAAK,EAAE,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC;AAAA,IAC5D,CAAC,EACA,KAAK,EAAE;AAAA,EAChB;AACJ;AAEO,IAAM,uBAAN,MAAkD;AAAA,EAGrD,YAAY,SAAyB;AACjC,SAAK,UAAU;AAAA,EACnB;AAAA,EAEM,qBACF,KACA,UACA,UACA,OACa;AAAA;AACb,YAAM,gBAAgB,KAAK;AAC3B,UAAI,CAAC,eAAe;AAChB,kBAAM,gBAAE,uBAAuB,CAAC;AAAA,MACpC;AACA,UAAI;AACA,cAAM,YAAY,MAAM,cAAc,SAAS,GAAG;AAClD,cAAM,CAAC,MAAM,SAAS,IAAI,UAAU,QAAQ,MAAM,SAAS;AAC3D,YAAI,QAAQ,KAAK,YAAY,EAAE,QAAQ,eAAe,IAAI,IAAI;AAC1D,mBAAS,iBAAiB,SAAS,CAAC;AAAA,QACxC,OAAO;AACH,oBAAM,gBAAE,yBAAyB,IAAI,YAAY,GAAG,EAAE,CAAC;AAAA,QAC3D;AAAA,MACJ,SAAS,GAAG;AACR,kBAAM,gBAAE,oBAAoB,GA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iBAAiB,SAAS,iBAAiB,GAAG;AAC9C;AAAA,UACI,2BAA2B,GAAG;AAAA,UAC9B;AAAA,QACJ;AAAA,MACJ,OAAO;AACH,cAAM,oBAAoB,GAAG,iBAAiB,EAAE,SAAS,CAAC,KAAK,CAAC;AAAA,MACpE;AAAA,IACJ,CAAC;AAAA,EACT;AACJ;AAEA,IAAqB,aAArB,MAAgC;AAAA,EAG5B,YAAY,aAAkD;AAF9D,SAAQ,cAAc,CAAC;AAGnB,SAAK,cAAc;AAAA,EACvB;AAAA,EAEA,qBACI,KACA,UACA,UACA,OACI;AAQJ,QAAI,WAAW;AACf,QAAI,QAAQ;AACZ,QAAI;AACA,iBAAW,IAAI,IAAI,GAAG,EAAE;AAAA,IAC5B,SAAS,GAAG;AACR,cAAQ;AAAA,IACZ;AAEA,QAAI,OAAO;AACP,UAAI;AACA,cAAM,CAAC,OAAO,EAAE,IAAI,SAAS,MAAM,GAAG;AACtC,YAAI,KAAK,YAAY,IAAI,GAAG;AAExB,eAAK,YAAY,IAAI,EAAE,qBAAqB,KAAK,UAAU,UAAU,KAAK;AAAA,QAC9E,OAAO;AAEH,gBAAM,6BAA6B,IAAI,uBAAuB,GAAG,EAAE;AAAA,QACvE;AAAA,MACJ,SAAS,GAAG;AACR,cAAM,qCAAqC,EAAE,OAAO,EAAE;AAAA,MAC1D;AAAA,IACJ,OAAO;AAGH,eAAS,GAAG;AAAA,IAChB;AAAA,EACJ;AACJ;",
6
6
  "names": []
7
7
  }
package/FileDownloader.js CHANGED
@@ -87,54 +87,39 @@ var Downloader = class {
87
87
  };
88
88
 
89
89
  // src/FileDownloader.tsx
90
- var FileDownloader = class extends react_exports.PureComponent {
91
- constructor(props) {
92
- super(props);
93
- this.state = {};
94
- }
95
- componentDidMount() {
96
- this.initiateDownload();
97
- }
98
- componentDidUpdate(prevProps) {
99
- if (this.props.url !== prevProps.url) {
100
- this.initiateDownload();
101
- }
102
- }
103
- initiateDownload() {
104
- this.setState({});
105
- const { url } = this.props;
106
- const downloader = new Downloader(this.props.protocolHandlers);
90
+ var FileDownloader = (props) => {
91
+ const [content, setContent] = react_exports.useState();
92
+ const [progress, setProgress] = react_exports.useState({
93
+ message: `Downloading ${props.url}...`,
94
+ bytesDownloaded: 0
95
+ });
96
+ const [error, setError] = react_exports.useState();
97
+ const {
98
+ url,
99
+ renderContent,
100
+ renderProgress,
101
+ renderError = (msg) => /* @__PURE__ */ react_exports.createElement("div", null, msg)
102
+ } = props;
103
+ react_exports.useEffect(() => {
104
+ const downloader = new Downloader(props.protocolHandlers);
107
105
  downloader.downloadWithProgress(
108
106
  url,
109
- (content) => this.setState({ content }),
107
+ (complete) => setContent(complete),
110
108
  // done downloading
111
- (progress) => {
112
- this.setState({ progress });
109
+ (currentProgress) => {
110
+ setProgress(currentProgress);
113
111
  },
114
112
  (msg) => {
115
- this.setState({ error: msg });
113
+ setError(msg);
116
114
  }
117
115
  );
116
+ }, [props.protocolHandlers, url]);
117
+ if (content) {
118
+ return renderContent(content);
118
119
  }
119
- render() {
120
- const {
121
- url,
122
- renderContent,
123
- renderProgress,
124
- renderError = (msg) => /* @__PURE__ */ react_exports.createElement("div", null, msg)
125
- } = this.props;
126
- const {
127
- content,
128
- progress = { message: `Downloading ${url}...`, bytesDownloaded: 0 },
129
- error
130
- } = this.state;
131
- if (content) {
132
- return renderContent(content);
133
- }
134
- if (error) {
135
- return renderError(error);
136
- }
137
- return typeof renderProgress === "function" ? renderProgress(progress) : /* @__PURE__ */ react_exports.createElement(react_exports.Fragment, null);
120
+ if (error) {
121
+ return renderError(error);
138
122
  }
123
+ return typeof renderProgress === "function" ? renderProgress(progress) : null;
139
124
  };
140
125
  //# sourceMappingURL=FileDownloader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/FileDownloader.tsx", "esm-externals:react", "esm-externals:@splunk/ui-utils/i18n", "src/Downloader.ts"],
4
- "sourcesContent": ["import * as React from 'react';\nimport Downloader, { IDownloader, DownloadProgress } from './Downloader';\n\n/**\n * The FileDownloader is passed a URL string, and render prop which allows a caller to control what is rendered\n * When the file is completely downloaded. This FileDownloader also displays basic text showing download progress.\n * If you want to supply your own custom renderer or progress and error you can do so as well.\n *\n */\nexport interface FileDownloaderProps {\n /**\n * The URL to download\n */\n url: string;\n /**\n * The render function that will render when the content is downloaded\n * @returns {React.Component}\n */\n renderContent: (content: string) => React.ReactElement;\n /**\n * An optional function to render progress (defaults to basic text display of progress)\n * @param {DownloadProgress} progress\n * @returns {React.Component}\n */\n renderProgress?: (progress: DownloadProgress) => React.Component;\n /**\n * An optional function to render errors (defaults to basic text display of errors)\n * @param {string} msg\n * @param {Error} error\n * @returns {React.Component}\n */\n renderError?: (msg: string, error?: Error) => React.Component;\n /**\n * A <key>:<Downloader> map for Downloader Component\n */\n protocolHandlers: { [key: string]: IDownloader };\n}\n\nexport class FileDownloader extends React.PureComponent<\n FileDownloaderProps,\n { content?: string; progress?: DownloadProgress; error?: string }\n> {\n constructor(props: FileDownloaderProps) {\n super(props);\n this.state = {};\n }\n\n componentDidMount(): void {\n this.initiateDownload();\n }\n\n componentDidUpdate(prevProps: FileDownloaderProps): void {\n if (this.props.url !== prevProps.url) {\n this.initiateDownload();\n }\n }\n\n initiateDownload(): void {\n this.setState({});\n const { url } = this.props;\n\n const downloader = new Downloader(this.props.protocolHandlers);\n downloader.downloadWithProgress(\n url,\n (content: string): void => this.setState({ content }), // done downloading\n (progress: DownloadProgress): void => {\n this.setState({ progress });\n },\n (msg: string): void => {\n this.setState({ error: msg });\n }\n );\n }\n\n render(): JSX.Element | React.Component {\n const {\n url,\n renderContent,\n renderProgress,\n renderError = (msg: string): JSX.Element => <div>{msg}</div>,\n } = this.props;\n const {\n content,\n progress = { message: `Downloading ${url}...`, bytesDownloaded: 0 },\n error,\n } = this.state;\n if (content) {\n return renderContent(content); // render prop\n }\n if (error) {\n return renderError(error);\n }\n return typeof renderProgress === 'function' ? renderProgress(progress) : <></>;\n }\n}\n", "\nimport * as defaultImport from \"react\";\nexport * from \"react\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"@splunk/ui-utils/i18n\";\nexport * from \"@splunk/ui-utils/i18n\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "/* eslint-disable max-classes-per-file */\n/* eslint-disable class-methods-use-this */\nimport { _ } from '@splunk/ui-utils/i18n';\nimport ImageRegistry from '@splunk/visualization-context/ImageRegistry';\n\nexport interface DownloadProgress {\n bytesDownloaded: number;\n contentLength?: number;\n message: string;\n}\nexport interface IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void;\n}\n\nexport const b64DecodeUnicode = (base64Data: string): string => {\n // from bytestream, to percent-encoding, to original string.\n return decodeURIComponent(\n atob(base64Data)\n .split('')\n .map((c: string): string => {\n return `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`;\n })\n .join('')\n );\n};\n\nexport class ImageRegistryFetcher implements IDownloader {\n context: ImageRegistry;\n\n constructor(context?: ImageRegistry) {\n this.context = context;\n }\n\n async downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): Promise<void> {\n const imageRegistry = this.context;\n if (!imageRegistry) {\n error(_('Missing Image Context'));\n }\n try {\n const imageData = await imageRegistry.getByURL(url);\n const [mime, svgBase64] = imageData.dataURI.split('base64,');\n if (mime && mime.toLowerCase().indexOf('image/svg+xml') > -1) {\n complete(b64DecodeUnicode(svgBase64));\n } else {\n error(_(`Unsupported MIME type ${mime} for url ${url}`));\n }\n } catch (e) {\n error(_(`Error retrieving ${url} from Image Registry, error was '${e.message}'`), e);\n }\n }\n}\n\nexport class URLDownloader implements IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // Step 1: fetch content from URL, get reader\n fetch(url)\n .then(\n async (response: Response): Promise<void> => {\n if (!response.ok) {\n const msg = `Fetch not Ok for ${url}, status was '${response.statusText}'`;\n console.warn(msg);\n error(msg);\n return;\n }\n const reader = response.body.getReader();\n\n // Step 2: get total length\n const contentLength = +response.headers.get('Content-Length');\n\n // Step 3: read the data\n let bytesDownloaded = 0; // length at the moment\n const chunks = []; // array of received binary chunks (comprises the body)\n let done = false;\n while (!done) {\n // eslint-disable-next-line no-await-in-loop\n const res = await reader.read();\n done = res.done;\n const { value } = res;\n if (value) {\n chunks.push(value);\n bytesDownloaded += value.length;\n progress({\n // call the progress callback...can enable the UI to show progress\n bytesDownloaded,\n contentLength,\n message: `Received ${bytesDownloaded} bytes of ${\n contentLength || 'unknown size'\n }`,\n });\n }\n }\n\n // Step 4: concatenate chunks into single Uint8Array\n const chunksAll = new Uint8Array(bytesDownloaded);\n let position = 0;\n // eslint-disable-next-line no-restricted-syntax\n for (const chunk of chunks) {\n chunksAll.set(chunk, position);\n position += chunk.length;\n }\n\n progress({\n bytesDownloaded,\n contentLength,\n message: 'decoding chunks',\n });\n\n // Step 5: decode into a string\n const svg = new TextDecoder('utf-8').decode(chunksAll);\n complete(svg); // show the downloaded svg back to the caller via its completion callback\n }\n )\n .catch((e: Error): void => {\n // Note: For CORS issue, fetch api call immediately fails without any status code or response and the error message says \"Failed to fetch\"\n // but for other issues (invalid url, not found, etc), it returns with a certain status code (406, 404, etc)\n // and empty response so further operation on the response data fails.\n const stringifiedError = e.toString();\n console.error(stringifiedError);\n // call the supplied error handling function\n if (stringifiedError.includes('Failed to fetch')) {\n error(\n `Cannot fetch the image \"${url}\" due to a cross-origin resource sharing (CORS) policy`,\n e\n );\n } else {\n error(`Fetch error for '${url}', error was '${e.toString()}'`, e);\n }\n });\n }\n}\n\nexport default class Downloader {\n private downloaders = {};\n\n constructor(downloaders: { [protocol: string]: IDownloader }) {\n this.downloaders = downloaders;\n }\n\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // url is the following:\n // data:image/svg+xml;base64....\n // http://\n // https://\n // local://\n // or otherwise return errors\n\n let protocol = '';\n let isUrl = true;\n try {\n protocol = new URL(url).protocol;\n } catch (e) {\n isUrl = false;\n }\n\n if (isUrl) {\n try {\n const [type = ''] = protocol.split(':');\n if (this.downloaders[type]) {\n // data, http(s), local....\n this.downloaders[type].downloadWithProgress(url, complete, progress, error);\n } else {\n // unknown type\n error(`Unsupported URL protocol '${type}' for SVG download: ${url}`);\n }\n } catch (e) {\n error(`Unexpected error downloading SVG: ${e.message}`);\n }\n } else {\n // the url might be literal content. <svg>...</svg>. This is kindof a hack where if you pass the downloader something\n // that is literal content, it will just return the content. Makes the code flow cleaner in layers above.\n complete(url);\n }\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AACA,oBAA+B;AAC/B,0BAAc;AACd,IAAO,gBAAS,aAAa,gBAA8B,wBAAU;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAA,iBAA+B;AAC/B,yBAAc;AACd,IAAO,eAAS,aAAaA,iBAA8B,yBAAUA;;;AC+IrE,IAAqB,aAArB,MAAgC;AAAA,EAG5B,YAAY,aAAkD;AAF9D,SAAQ,cAAc,CAAC;AAGnB,SAAK,cAAc;AAAA,EACvB;AAAA,EAEA,qBACI,KACA,UACA,UACA,OACI;AAQJ,QAAI,WAAW;AACf,QAAI,QAAQ;AACZ,QAAI;AACA,iBAAW,IAAI,IAAI,GAAG,EAAE;AAAA,IAC5B,SAAS,GAAG;AACR,cAAQ;AAAA,IACZ;AAEA,QAAI,OAAO;AACP,UAAI;AACA,cAAM,CAAC,OAAO,EAAE,IAAI,SAAS,MAAM,GAAG;AACtC,YAAI,KAAK,YAAY,IAAI,GAAG;AAExB,eAAK,YAAY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aAAO,cAAc,OAAO;AAAA,IAChC;AACA,QAAI,OAAO;AACP,aAAO,YAAY,KAAK;AAAA,IAC5B;AACA,WAAO,OAAO,mBAAmB,aAAa,eAAe,QAAQ,IAAI,wEAAE;AAAA,EAC/E;AACJ;",
4
+ "sourcesContent": ["import * as React from 'react';\nimport Downloader, { IDownloader, DownloadProgress } from './Downloader';\n\nexport interface FileDownloaderProps {\n /**\n * The URL to download\n */\n url: string;\n /**\n * The render function that will render when the content is downloaded\n * @returns {JSX.Element}\n */\n renderContent: (content: string) => JSX.Element;\n /**\n * An optional function to render progress (defaults to basic text display of progress)\n * @param {DownloadProgress} progress\n * @returns {JSX.Element}\n */\n renderProgress?: (progress: DownloadProgress) => JSX.Element;\n /**\n * An optional function to render errors (defaults to basic text display of errors)\n * @param {string} msg\n * @param {Error} error\n * @returns {JSX.Element}\n */\n renderError?: (msg: string, error?: Error) => JSX.Element;\n /**\n * A <key>:<Downloader> map for Downloader Component\n */\n protocolHandlers: { [key: string]: IDownloader };\n}\n\nexport const FileDownloader = (props: FileDownloaderProps): JSX.Element => {\n const [content, setContent] = React.useState<string>();\n const [progress, setProgress] = React.useState<DownloadProgress>({\n message: `Downloading ${props.url}...`,\n bytesDownloaded: 0,\n });\n const [error, setError] = React.useState<string>();\n const {\n url,\n renderContent,\n renderProgress,\n renderError = (msg: string): JSX.Element => <div>{msg}</div>,\n } = props;\n React.useEffect(() => {\n const downloader = new Downloader(props.protocolHandlers);\n downloader.downloadWithProgress(\n url,\n complete => setContent(complete), // done downloading\n (currentProgress: DownloadProgress): void => {\n setProgress(currentProgress);\n },\n (msg: string): void => {\n setError(msg);\n }\n );\n }, [props.protocolHandlers, url]);\n if (content) {\n return renderContent(content);\n }\n if (error) {\n return renderError(error);\n }\n return typeof renderProgress === 'function' ? renderProgress(progress) : null;\n};\n", "\nimport * as defaultImport from \"react\";\nexport * from \"react\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"@splunk/ui-utils/i18n\";\nexport * from \"@splunk/ui-utils/i18n\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "/* eslint-disable max-classes-per-file */\n/* eslint-disable class-methods-use-this */\nimport { _ } from '@splunk/ui-utils/i18n';\nimport ImageRegistry from '@splunk/visualization-context/ImageRegistry';\n\nexport interface DownloadProgress {\n bytesDownloaded: number;\n contentLength?: number;\n message: string;\n}\nexport interface IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void;\n}\n\nexport const b64DecodeUnicode = (base64Data: string): string => {\n // from bytestream, to percent-encoding, to original string.\n return decodeURIComponent(\n atob(base64Data)\n .split('')\n .map((c: string): string => {\n return `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`;\n })\n .join('')\n );\n};\n\nexport class ImageRegistryFetcher implements IDownloader {\n context: ImageRegistry;\n\n constructor(context?: ImageRegistry) {\n this.context = context;\n }\n\n async downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): Promise<void> {\n const imageRegistry = this.context;\n if (!imageRegistry) {\n error(_('Missing Image Context'));\n }\n try {\n const imageData = await imageRegistry.getByURL(url);\n const [mime, svgBase64] = imageData.dataURI.split('base64,');\n if (mime && mime.toLowerCase().indexOf('image/svg+xml') > -1) {\n complete(b64DecodeUnicode(svgBase64));\n } else {\n error(_(`Unsupported MIME type ${mime} for url ${url}`));\n }\n } catch (e) {\n error(_(`Error retrieving ${url} from Image Registry, error was '${e.message}'`), e);\n }\n }\n}\n\nexport class URLDownloader implements IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // Step 1: fetch content from URL, get reader\n fetch(url)\n .then(async (response: Response): Promise<void> => {\n if (!response.ok) {\n const msg = `Fetch not Ok for ${url}, status was '${response.statusText}'`;\n // eslint-disable-next-line no-console\n console.warn(msg);\n error(msg);\n return;\n }\n const reader = response.body.getReader();\n\n // Step 2: get total length\n const contentLength = +response.headers.get('Content-Length');\n\n // Step 3: read the data\n let bytesDownloaded = 0; // length at the moment\n const chunks = []; // array of received binary chunks (comprises the body)\n let done = false;\n while (!done) {\n // eslint-disable-next-line no-await-in-loop\n const res = await reader.read();\n if (!res) {\n return;\n }\n done = res.done;\n const { value } = res;\n if (value) {\n chunks.push(value);\n bytesDownloaded += value.length;\n progress({\n // call the progress callback...can enable the UI to show progress\n bytesDownloaded,\n contentLength,\n message: `Received ${bytesDownloaded} bytes of ${\n contentLength || 'unknown size'\n }`,\n });\n }\n }\n\n // Step 4: concatenate chunks into single Uint8Array\n const chunksAll = new Uint8Array(bytesDownloaded);\n let position = 0;\n // eslint-disable-next-line no-restricted-syntax\n for (const chunk of chunks) {\n chunksAll.set(chunk, position);\n position += chunk.length;\n }\n\n progress({\n bytesDownloaded,\n contentLength,\n message: 'decoding chunks',\n });\n\n // Step 5: decode into a string\n const svg = new TextDecoder('utf-8').decode(chunksAll);\n complete(svg); // show the downloaded svg back to the caller via its completion callback\n })\n .catch((e: Error): void => {\n // Note: For CORS issue, fetch api call immediately fails without any status code or response and the error message says \"Failed to fetch\"\n // but for other issues (invalid url, not found, etc), it returns with a certain status code (406, 404, etc)\n // and empty response so further operation on the response data fails.\n const stringifiedError = e.toString();\n // eslint-disable-next-line no-console\n console.error(stringifiedError);\n // call the supplied error handling function\n if (stringifiedError.includes('Failed to fetch')) {\n error(\n `Cannot fetch the image \"${url}\" due to a cross-origin resource sharing (CORS) policy`,\n e\n );\n } else {\n error(`Fetch error for '${url}', error was '${e.toString()}'`, e);\n }\n });\n }\n}\n\nexport default class Downloader {\n private downloaders = {};\n\n constructor(downloaders: { [protocol: string]: IDownloader }) {\n this.downloaders = downloaders;\n }\n\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // url is the following:\n // data:image/svg+xml;base64....\n // http://\n // https://\n // local://\n // or otherwise return errors\n\n let protocol = '';\n let isUrl = true;\n try {\n protocol = new URL(url).protocol;\n } catch (e) {\n isUrl = false;\n }\n\n if (isUrl) {\n try {\n const [type = ''] = protocol.split(':');\n if (this.downloaders[type]) {\n // data, http(s), local....\n this.downloaders[type].downloadWithProgress(url, complete, progress, error);\n } else {\n // unknown type\n error(`Unsupported URL protocol '${type}' for SVG download: ${url}`);\n }\n } catch (e) {\n error(`Unexpected error downloading SVG: ${e.message}`);\n }\n } else {\n // the url might be literal content. <svg>...</svg>. This is kindof a hack where if you pass the downloader something\n // that is literal content, it will just return the content. Makes the code flow cleaner in layers above.\n complete(url);\n }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AACA,oBAA+B;AAC/B,0BAAc;AACd,IAAO,gBAAS,aAAa,gBAA8B,wBAAU;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAA,iBAA+B;AAC/B,yBAAc;AACd,IAAO,eAAS,aAAaA,iBAA8B,yBAAUA;;;ACkJrE,IAAqB,aAArB,MAAgC;AAAA,EAG5B,YAAY,aAAkD;AAF9D,SAAQ,cAAc,CAAC;AAGnB,SAAK,cAAc;AAAA,EACvB;AAAA,EAEA,qBACI,KACA,UACA,UACA,OACI;AAQJ,QAAI,WAAW;AACf,QAAI,QAAQ;AACZ,QAAI;AACA,iBAAW,IAAI,IAAI,GAAG,EAAE;AAAA,IAC5B,SAAS,GAAG;AACR,cAAQ;AAAA,IACZ;AAEA,QAAI,OAAO;AACP,UAAI;AACA,cAAM,CAAC,OAAO,EAAE,IAAI,SAAS,MAAM,GAAG;AACtC,YAAI,KAAK,YAAY,IAAI,GAAG;AAExB,eAAK,YAAY,IAAI,EAAE,qBAAqB,KAAK,UAAU,UAAU,KAAK;AAAA,QAC9E,OAAO;AAEH,gBAAM,6BAA6B,IAAI,uBAAuB,GAAG,EAAE;AAAA,QACvE;AAAA,MACJ,SAAS,GAAG;AACR,cAAM,qCAAqC,EAAE,OAAO,EAAE;AAAA,MAC1D;AAAA,IACJ,OAAO;AAGH,eAAS,GAAG;AAAA,IAChB;AAAA,EACJ;AACJ;;;AHpKO,IAAM,iBAAiB,CAAC,UAA4C;AACvE,QAAM,CAAC,SAAS,UAAU,IAAU,uBAAiB;AACrD,QAAM,CAAC,UAAU,WAAW,IAAU,uBAA2B;AAAA,IAC7D,SAAS,eAAe,MAAM,GAAG;AAAA,IACjC,iBAAiB;AAAA,EACrB,CAAC;AACD,QAAM,CAAC,OAAO,QAAQ,IAAU,uBAAiB;AACjD,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,CAAC,QAA6B,4CAAC,aAAK,GAAI;AAAA,EAC1D,IAAI;AACJ,EAAM,wBAAU,MAAM;AAClB,UAAM,aAAa,IAAI,WAAW,MAAM,gBAAgB;AACxD,eAAW;AAAA,MACP;AAAA,MACA,cAAY,WAAW,QAAQ;AAAA;AAAA,MAC/B,CAAC,oBAA4C;AACzC,oBAAY,eAAe;AAAA,MAC/B;AAAA,MACA,CAAC,QAAsB;AACnB,iBAAS,GAAG;AAAA,MAChB;AAAA,IACJ;AAAA,EACJ,GAAG,CAAC,MAAM,kBAAkB,GAAG,CAAC;AAChC,MAAI,SAAS;AACT,WAAO,cAAc,OAAO;AAAA,EAChC;AACA,MAAI,OAAO;AACP,WAAO,YAAY,KAAK;AAAA,EAC5B;AACA,SAAO,OAAO,mBAAmB,aAAa,eAAe,QAAQ,IAAI;AAC7E;",
6
6
  "names": ["defaultImport"]
7
7
  }
package/Message.js CHANGED
@@ -30,7 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // src/Message.jsx
33
+ // src/Message.tsx
34
34
  var Message_exports2 = {};
35
35
  __export(Message_exports2, {
36
36
  default: () => Message_default2
@@ -46,41 +46,32 @@ var defaultImport = __toESM(require("react"));
46
46
  __reExport(react_exports, require("react"));
47
47
  var react_default = "default" in defaultImport ? defaultImport.default : defaultImport;
48
48
 
49
- // esm-externals:prop-types
50
- var prop_types_exports = {};
51
- __export(prop_types_exports, {
52
- default: () => prop_types_default
53
- });
54
- var defaultImport2 = __toESM(require("prop-types"));
55
- __reExport(prop_types_exports, require("prop-types"));
56
- var prop_types_default = "default" in defaultImport2 ? defaultImport2.default : defaultImport2;
57
-
58
49
  // esm-externals:styled-components
59
50
  var styled_components_exports = {};
60
51
  __export(styled_components_exports, {
61
52
  default: () => styled_components_default
62
53
  });
63
- var defaultImport3 = __toESM(require("styled-components"));
54
+ var defaultImport2 = __toESM(require("styled-components"));
64
55
  __reExport(styled_components_exports, require("styled-components"));
65
- var styled_components_default = "default" in defaultImport3 ? defaultImport3.default : defaultImport3;
56
+ var styled_components_default = "default" in defaultImport2 ? defaultImport2.default : defaultImport2;
66
57
 
67
58
  // esm-externals:@splunk/react-ui/Message
68
59
  var Message_exports = {};
69
60
  __export(Message_exports, {
70
61
  default: () => Message_default
71
62
  });
72
- var defaultImport4 = __toESM(require("@splunk/react-ui/Message"));
63
+ var defaultImport3 = __toESM(require("@splunk/react-ui/Message"));
73
64
  __reExport(Message_exports, require("@splunk/react-ui/Message"));
74
- var Message_default = "default" in defaultImport4 ? defaultImport4.default : defaultImport4;
65
+ var Message_default = "default" in defaultImport3 ? defaultImport3.default : defaultImport3;
75
66
 
76
67
  // esm-externals:lodash/isNumber
77
68
  var isNumber_exports = {};
78
69
  __export(isNumber_exports, {
79
70
  default: () => isNumber_default
80
71
  });
81
- var defaultImport5 = __toESM(require("lodash/isNumber"));
72
+ var defaultImport4 = __toESM(require("lodash/isNumber"));
82
73
  __reExport(isNumber_exports, require("lodash/isNumber"));
83
- var isNumber_default = "default" in defaultImport5 ? defaultImport5.default : defaultImport5;
74
+ var isNumber_default = "default" in defaultImport4 ? defaultImport4.default : defaultImport4;
84
75
 
85
76
  // src/style.js
86
77
  var toPx = (number, defaultNumber = 0) => isNumber_default(number) ? `${number}px` : number || toPx(defaultNumber);
@@ -95,7 +86,7 @@ var toDimension = ({ width, height }) => {
95
86
  return css;
96
87
  };
97
88
 
98
- // src/Message.jsx
89
+ // src/Message.tsx
99
90
  var MessageContainer = styled_components_default.div`
100
91
  overflow: hidden;
101
92
  display: flex;
@@ -103,28 +94,6 @@ var MessageContainer = styled_components_default.div`
103
94
  align-items: center;
104
95
  ${(p) => toDimension({ width: p.width, height: p.height })};
105
96
  `;
106
- var Message = ({ width, height, level, message }) => /* @__PURE__ */ react_default.createElement(MessageContainer, { width, height, "data-test": "visualization-message" }, /* @__PURE__ */ react_default.createElement(Message_default, { type: level, style: { maxWidth: "100%" } }, message));
107
- Message.propTypes = {
108
- /**
109
- * width in pixel or string, defaults to 100%
110
- */
111
- width: prop_types_default.oneOfType([prop_types_default.string, prop_types_default.number]),
112
- /**
113
- * height in pixel or string
114
- */
115
- height: prop_types_default.oneOfType([prop_types_default.string, prop_types_default.number]),
116
- /**
117
- * message text
118
- */
119
- message: prop_types_default.string,
120
- /**
121
- * message level
122
- */
123
- level: prop_types_default.oneOf(["info", "warning", "error"])
124
- };
125
- Message.defaultProps = {
126
- level: "info",
127
- message: ""
128
- };
129
- var Message_default2 = react_default.memo(Message);
97
+ var Message = ({ width, height, level = "info", message = "" }) => /* @__PURE__ */ react_exports.createElement(MessageContainer, { width, height, "data-test": "visualization-message" }, /* @__PURE__ */ react_exports.createElement(Message_default, { type: level, style: { maxWidth: "100%" } }, message));
98
+ var Message_default2 = react_exports.memo(Message);
130
99
  //# sourceMappingURL=Message.js.map
package/Message.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["src/Message.jsx", "esm-externals:react", "esm-externals:prop-types", "esm-externals:styled-components", "esm-externals:@splunk/react-ui/Message", "esm-externals:lodash/isNumber", "src/style.js"],
4
- "sourcesContent": ["import React from 'react';\nimport T from 'prop-types';\nimport styled from 'styled-components';\nimport SplunkUIMessage from '@splunk/react-ui/Message';\nimport { toDimension } from './style';\n\nconst MessageContainer = styled.div`\n overflow: hidden;\n display: flex;\n justify-content: center;\n align-items: center;\n ${p => toDimension({ width: p.width, height: p.height })};\n`;\n\n/**\n * A component that display message\n *\n */\nconst Message = ({ width, height, level, message }) => (\n <MessageContainer width={width} height={height} data-test=\"visualization-message\">\n <SplunkUIMessage type={level} style={{ maxWidth: '100%' }}>\n {message}\n </SplunkUIMessage>\n </MessageContainer>\n);\n\nMessage.propTypes = {\n /**\n * width in pixel or string, defaults to 100%\n */\n width: T.oneOfType([T.string, T.number]),\n /**\n * height in pixel or string\n */\n height: T.oneOfType([T.string, T.number]),\n /**\n * message text\n */\n message: T.string,\n /**\n * message level\n */\n level: T.oneOf(['info', 'warning', 'error']),\n};\n\nMessage.defaultProps = {\n level: 'info',\n message: '',\n};\nexport default React.memo(Message);\n", "\nimport * as defaultImport from \"react\";\nexport * from \"react\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"prop-types\";\nexport * from \"prop-types\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"styled-components\";\nexport * from \"styled-components\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"@splunk/react-ui/Message\";\nexport * from \"@splunk/react-ui/Message\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"lodash/isNumber\";\nexport * from \"lodash/isNumber\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "import isNumber from 'lodash/isNumber';\n\n/**\n * convert number to px\n * @param {*} number\n */\nexport const toPx = (number, defaultNumber = 0) =>\n isNumber(number) ? `${number}px` : number || toPx(defaultNumber);\n\n/**\n * generate width/height css properties\n * @param {*} param0\n */\nexport const toDimension = ({ width, height }) => {\n let css = '';\n if (width) {\n css = `width: ${toPx(width)};`;\n }\n if (height) {\n // only add a linebreak if width was also set\n css = `${css}${width ? '\\n' : ''}height: ${toPx(height)};`;\n }\n return css;\n};\n\n/**\n * generate margin css property\n */\nexport const arrayToCSSProp = (prop, vals = [0, 0, 0, 0]) => {\n if (Array.isArray(vals)) {\n return `\n ${prop}: ${toPx(vals[0])} ${toPx(vals[1])} ${toPx(vals[2])} ${toPx(vals[3])};\n `;\n }\n\n return `${prop}: ${toPx(vals)};`;\n};\n\n/**\n * generate margin css property\n */\nexport const toMargin = (margins = [0, 0, 0, 0]) => arrayToCSSProp('margin', margins);\n\n/**\n * generate padding css property\n */\nexport const toPadding = (paddings = [0, 0, 0, 0]) => arrayToCSSProp('padding', paddings);\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,mBAAA;AAAA,SAAAA,kBAAA;AAAA,iBAAAC;AAAA;AAAA,8BAAAD;;;ACAA;AAAA;AAAA;AAAA;AACA,oBAA+B;AAC/B,0BAAc;AACd,IAAO,gBAAS,aAAa,gBAA8B,wBAAU;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAE,iBAA+B;AAC/B,+BAAc;AACd,IAAO,qBAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,sCAAc;AACd,IAAO,4BAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,4BAAc;AACd,IAAO,kBAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,6BAAc;AACd,IAAO,mBAAS,aAAaA,iBAA8B,yBAAUA;;;ACG9D,IAAM,OAAO,CAAC,QAAQ,gBAAgB,MACzC,iBAAS,MAAM,IAAI,GAAG,MAAM,OAAO,UAAU,KAAK,aAAa;AAM5D,IAAM,cAAc,CAAC,EAAE,OAAO,OAAO,MAAM;AAC9C,MAAI,MAAM;AACV,MAAI,OAAO;AACP,UAAM,UAAU,KAAK,KAAK,CAAC;AAAA,EAC/B;AACA,MAAI,QAAQ;AAER,UAAM,GAAG,GAAG,GAAG,QAAQ,OAAO,EAAE,WAAW,KAAK,MAAM,CAAC;AAAA,EAC3D;AACA,SAAO;AACX;;;ANjBA,IAAM,mBAAmB,0BAAO;AAAA;AAAA;AAAA;AAAA;AAAA,MAK1B,OAAK,YAAY,EAAE,OAAO,EAAE,OAAO,QAAQ,EAAE,OAAO,CAAC,CAAC;AAAA;AAO5D,IAAM,UAAU,CAAC,EAAE,OAAO,QAAQ,OAAO,QAAQ,MAC7C,4CAAC,oBAAiB,OAAc,QAAgB,aAAU,2BACtD,4CAAC,mBAAgB,MAAM,OAAO,OAAO,EAAE,UAAU,OAAO,KACnD,OACL,CACJ;AAGJ,QAAQ,YAAY;AAAA;AAAA;AAAA;AAAA,EAIhB,OAAO,mBAAE,UAAU,CAAC,mBAAE,QAAQ,mBAAE,MAAM,CAAC;AAAA;AAAA;AAAA;AAAA,EAIvC,QAAQ,mBAAE,UAAU,CAAC,mBAAE,QAAQ,mBAAE,MAAM,CAAC;AAAA;AAAA;AAAA;AAAA,EAIxC,SAAS,mBAAE;AAAA;AAAA;AAAA;AAAA,EAIX,OAAO,mBAAE,MAAM,CAAC,QAAQ,WAAW,OAAO,CAAC;AAC/C;AAEA,QAAQ,eAAe;AAAA,EACnB,OAAO;AAAA,EACP,SAAS;AACb;AACA,IAAOC,mBAAQ,cAAM,KAAK,OAAO;",
6
- "names": ["Message_exports", "Message_default", "defaultImport", "defaultImport", "defaultImport", "defaultImport", "Message_default"]
3
+ "sources": ["src/Message.tsx", "esm-externals:react", "esm-externals:styled-components", "esm-externals:@splunk/react-ui/Message", "esm-externals:lodash/isNumber", "src/style.js"],
4
+ "sourcesContent": ["import * as React from 'react';\nimport styled from 'styled-components';\nimport SplunkUIMessage from '@splunk/react-ui/Message';\nimport { toDimension } from './style';\n\nconst MessageContainer = styled.div<{ width: string | number; height: string | number }>`\n overflow: hidden;\n display: flex;\n justify-content: center;\n align-items: center;\n ${p => toDimension({ width: p.width, height: p.height })};\n`;\n\ntype MessageProps = {\n width: string | number;\n height: string | number;\n level: 'info' | 'warning' | 'error';\n message: string;\n};\n\nconst Message = ({ width, height, level = 'info', message = '' }: MessageProps) => (\n <MessageContainer width={width} height={height} data-test=\"visualization-message\">\n <SplunkUIMessage type={level} style={{ maxWidth: '100%' }}>\n {message}\n </SplunkUIMessage>\n </MessageContainer>\n);\n\nexport default React.memo(Message);\n", "\nimport * as defaultImport from \"react\";\nexport * from \"react\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"styled-components\";\nexport * from \"styled-components\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"@splunk/react-ui/Message\";\nexport * from \"@splunk/react-ui/Message\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"lodash/isNumber\";\nexport * from \"lodash/isNumber\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "import isNumber from 'lodash/isNumber';\n\n/**\n * convert number to px\n * @param {*} number\n */\nexport const toPx = (number, defaultNumber = 0) =>\n isNumber(number) ? `${number}px` : number || toPx(defaultNumber);\n\n/**\n * generate width/height css properties\n * @param {*} param0\n */\nexport const toDimension = ({ width, height }) => {\n let css = '';\n if (width) {\n css = `width: ${toPx(width)};`;\n }\n if (height) {\n // only add a linebreak if width was also set\n css = `${css}${width ? '\\n' : ''}height: ${toPx(height)};`;\n }\n return css;\n};\n\n/**\n * generate margin css property\n */\nexport const arrayToCSSProp = (prop, vals = [0, 0, 0, 0]) => {\n if (Array.isArray(vals)) {\n return `\n ${prop}: ${toPx(vals[0])} ${toPx(vals[1])} ${toPx(vals[2])} ${toPx(vals[3])};\n `;\n }\n\n return `${prop}: ${toPx(vals)};`;\n};\n\n/**\n * generate margin css property\n */\nexport const toMargin = (margins = [0, 0, 0, 0]) => arrayToCSSProp('margin', margins);\n\n/**\n * generate padding css property\n */\nexport const toPadding = (paddings = [0, 0, 0, 0]) => arrayToCSSProp('padding', paddings);\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,mBAAA;AAAA,SAAAA,kBAAA;AAAA,iBAAAC;AAAA;AAAA,8BAAAD;;;ACAA;AAAA;AAAA;AAAA;AACA,oBAA+B;AAC/B,0BAAc;AACd,IAAO,gBAAS,aAAa,gBAA8B,wBAAU;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAE,iBAA+B;AAC/B,sCAAc;AACd,IAAO,4BAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,4BAAc;AACd,IAAO,kBAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,6BAAc;AACd,IAAO,mBAAS,aAAaA,iBAA8B,yBAAUA;;;ACG9D,IAAM,OAAO,CAAC,QAAQ,gBAAgB,MACzC,iBAAS,MAAM,IAAI,GAAG,MAAM,OAAO,UAAU,KAAK,aAAa;AAM5D,IAAM,cAAc,CAAC,EAAE,OAAO,OAAO,MAAM;AAC9C,MAAI,MAAM;AACV,MAAI,OAAO;AACP,UAAM,UAAU,KAAK,KAAK,CAAC;AAAA,EAC/B;AACA,MAAI,QAAQ;AAER,UAAM,GAAG,GAAG,GAAG,QAAQ,OAAO,EAAE,WAAW,KAAK,MAAM,CAAC;AAAA,EAC3D;AACA,SAAO;AACX;;;ALlBA,IAAM,mBAAmB,0BAAO;AAAA;AAAA;AAAA;AAAA;AAAA,MAK1B,OAAK,YAAY,EAAE,OAAO,EAAE,OAAO,QA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