@splunk/visualizations-shared 28.0.0 → 28.2.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 +5 -0
- package/Downloader.d.ts +25 -0
- package/Downloader.js +16 -15
- package/Downloader.js.map +2 -2
- package/FileDownloader.d.ts +32 -0
- package/FileDownloader.js.map +2 -2
- package/FileDownloader.test.d.ts +1 -0
- package/JSONSchemaUtils.d.ts +9 -0
- package/Message.d.ts +9 -0
- package/Message.js +10 -41
- package/Message.js.map +4 -4
- package/RemoteIcon.d.ts +35 -0
- package/RemoteIcon.js +23 -46
- package/RemoteIcon.js.map +4 -4
- package/RemoteImage.d.ts +27 -0
- package/RemoteImage.js +21 -42
- package/RemoteImage.js.map +4 -4
- package/SanitizeProps.d.ts +19 -0
- package/SizeAwareWrapper.d.ts +23 -0
- package/SizeAwareWrapper.js +16 -29
- package/SizeAwareWrapper.js.map +3 -3
- package/VisualizationDocPage.d.ts +32 -0
- package/VisualizationDocPage.js +34 -88
- package/VisualizationDocPage.js.map +4 -4
- package/colorUtils.d.ts +1 -0
- package/configUtils.d.ts +2 -0
- package/dataSourceUtils.d.ts +27 -0
- package/hocUtils.d.ts +1 -0
- package/iconUtils.d.ts +15 -0
- package/mapUtils.d.ts +2 -0
- package/package.json +15 -15
- package/previewVizMessage.d.ts +2 -0
- package/schemaUtils.d.ts +1 -0
- package/style.d.ts +5 -0
- package/trellisUtils.d.ts +21 -0
- package/tsconfig.json +9 -8
- package/SizeAwareWrapperDeprecated.js +0 -145
- package/SizeAwareWrapperDeprecated.js.map +0 -7
package/.eslintrc.json
ADDED
package/Downloader.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import ImageRegistry from '@splunk/visualization-context/ImageRegistry';
|
|
2
|
+
export interface DownloadProgress {
|
|
3
|
+
bytesDownloaded: number;
|
|
4
|
+
contentLength?: number;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IDownloader {
|
|
8
|
+
downloadWithProgress(url: string, complete: (svg: string) => void, progress?: (p: DownloadProgress) => void, error?: (msg: string, error?: Error) => void): void | Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare const b64DecodeUnicode: (base64Data: string) => string;
|
|
11
|
+
export declare class ImageRegistryFetcher implements IDownloader {
|
|
12
|
+
context: ImageRegistry;
|
|
13
|
+
constructor(context?: ImageRegistry);
|
|
14
|
+
downloadWithProgress(url: string, complete: (svg: string) => void, progress?: (p: DownloadProgress) => void, error?: (msg: string, error?: Error) => void): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export declare class URLDownloader implements IDownloader {
|
|
17
|
+
downloadWithProgress(url: string, complete: (svg: string) => void, progress?: (p: DownloadProgress) => void, error?: (msg: string, error?: Error) => void): void;
|
|
18
|
+
}
|
|
19
|
+
export default class Downloader {
|
|
20
|
+
private downloaders;
|
|
21
|
+
constructor(downloaders: {
|
|
22
|
+
[protocol: string]: IDownloader;
|
|
23
|
+
});
|
|
24
|
+
downloadWithProgress(url: string, complete: (svg: string) => void, progress?: (p: DownloadProgress) => void, error?: (msg: string, error?: Error) => void): void;
|
|
25
|
+
}
|
package/Downloader.js
CHANGED
|
@@ -82,22 +82,20 @@ var ImageRegistryFetcher = class {
|
|
|
82
82
|
this.context = context;
|
|
83
83
|
}
|
|
84
84
|
downloadWithProgress(url, complete, progress, error) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
error((0, i18n_exports._)(`Unsupported MIME type ${mime} for url ${url}`));
|
|
97
|
-
}
|
|
98
|
-
} catch (e) {
|
|
99
|
-
error((0, i18n_exports._)(`Error retrieving ${url} from Image Registry, error was '${e.message}'`), e);
|
|
85
|
+
const imageRegistry = this.context;
|
|
86
|
+
if (!imageRegistry) {
|
|
87
|
+
error((0, i18n_exports._)("Missing Image Context"));
|
|
88
|
+
return Promise.resolve();
|
|
89
|
+
}
|
|
90
|
+
return imageRegistry.getByURL(url).then((imageData) => {
|
|
91
|
+
const [mime, svgBase64] = imageData.dataURI.split("base64,");
|
|
92
|
+
if (mime && mime.toLowerCase().indexOf("image/svg+xml") > -1) {
|
|
93
|
+
complete(b64DecodeUnicode(svgBase64));
|
|
94
|
+
} else {
|
|
95
|
+
error((0, i18n_exports._)(`Unsupported MIME type ${mime} for url ${url}`));
|
|
100
96
|
}
|
|
97
|
+
}).catch((e) => {
|
|
98
|
+
error((0, i18n_exports._)(`Error retrieving ${url} from Image Registry, error was '${e.message}'`), e);
|
|
101
99
|
});
|
|
102
100
|
}
|
|
103
101
|
};
|
|
@@ -117,6 +115,9 @@ var URLDownloader = class {
|
|
|
117
115
|
let done = false;
|
|
118
116
|
while (!done) {
|
|
119
117
|
const res = yield reader.read();
|
|
118
|
+
if (!res) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
120
121
|
done = res.done;
|
|
121
122
|
const { value } = res;
|
|
122
123
|
if (value) {
|
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
|
|
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,
|
|
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 | Promise<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 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 return Promise.resolve();\n }\n\n return imageRegistry\n .getByURL(url)\n .then(imageData => {\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 })\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": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IDownloader, DownloadProgress } from './Downloader';
|
|
2
|
+
export interface FileDownloaderProps {
|
|
3
|
+
/**
|
|
4
|
+
* The URL to download
|
|
5
|
+
*/
|
|
6
|
+
url: string;
|
|
7
|
+
/**
|
|
8
|
+
* The render function that will render when the content is downloaded
|
|
9
|
+
* @returns {JSX.Element}
|
|
10
|
+
*/
|
|
11
|
+
renderContent: (content: string) => JSX.Element;
|
|
12
|
+
/**
|
|
13
|
+
* An optional function to render progress (defaults to basic text display of progress)
|
|
14
|
+
* @param {DownloadProgress} progress
|
|
15
|
+
* @returns {JSX.Element}
|
|
16
|
+
*/
|
|
17
|
+
renderProgress?: (progress: DownloadProgress) => JSX.Element;
|
|
18
|
+
/**
|
|
19
|
+
* An optional function to render errors (defaults to basic text display of errors)
|
|
20
|
+
* @param {string} msg
|
|
21
|
+
* @param {Error} error
|
|
22
|
+
* @returns {JSX.Element}
|
|
23
|
+
*/
|
|
24
|
+
renderError?: (msg: string, error?: Error) => JSX.Element;
|
|
25
|
+
/**
|
|
26
|
+
* A <key>:<Downloader> map for Downloader Component
|
|
27
|
+
*/
|
|
28
|
+
protocolHandlers: {
|
|
29
|
+
[key: string]: IDownloader;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export declare const FileDownloader: (props: FileDownloaderProps) => JSX.Element;
|
package/FileDownloader.js.map
CHANGED
|
@@ -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\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 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;;;
|
|
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 | Promise<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 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 return Promise.resolve();\n }\n\n return imageRegistry\n .getByURL(url)\n .then(imageData => {\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 })\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;;;ACsJrE,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;;;AHxKO,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
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JSONSchema7, JSONSchema7Definition } from 'json-schema';
|
|
2
|
+
interface OptionsSchema {
|
|
3
|
+
[key: string]: JSONSchema7;
|
|
4
|
+
}
|
|
5
|
+
interface KV {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
export declare const pickFieldFromJSONSchema: (optionsSchema: OptionsSchema | JSONSchema7Definition, fieldName?: string) => KV;
|
|
9
|
+
export {};
|
package/Message.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
type MessageProps = {
|
|
3
|
+
width: string | number;
|
|
4
|
+
height: string | number;
|
|
5
|
+
level: 'info' | 'warning' | 'error';
|
|
6
|
+
message: string;
|
|
7
|
+
};
|
|
8
|
+
declare const _default: React.MemoExoticComponent<({ width, height, level, message }: MessageProps) => React.JSX.Element>;
|
|
9
|
+
export default _default;
|
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.
|
|
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
|
|
54
|
+
var defaultImport2 = __toESM(require("styled-components"));
|
|
64
55
|
__reExport(styled_components_exports, require("styled-components"));
|
|
65
|
-
var styled_components_default = "default" in
|
|
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
|
|
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
|
|
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
|
|
72
|
+
var defaultImport4 = __toESM(require("lodash/isNumber"));
|
|
82
73
|
__reExport(isNumber_exports, require("lodash/isNumber"));
|
|
83
|
-
var isNumber_default = "default" in
|
|
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.
|
|
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__ */
|
|
107
|
-
|
|
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.
|
|
4
|
-
"sourcesContent": ["import React from 'react';\nimport
|
|
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
|
|
6
|
-
"names": ["Message_exports", "Message_default", "defaultImport", "defaultImport", "defaultImport", "
|
|
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,QAAQ,EAAE,OAAO,CAAC,CAAC;AAAA;AAU5D,IAAM,UAAU,CAAC,EAAE,OAAO,QAAQ,QAAQ,QAAQ,UAAU,GAAG,MAC3D,4CAAC,oBAAiB,OAAc,QAAgB,aAAU,2BACtD,4CAAC,mBAAgB,MAAM,OAAO,OAAO,EAAE,UAAU,OAAO,KACnD,OACL,CACJ;AAGJ,IAAOC,mBAAc,mBAAK,OAAO;",
|
|
6
|
+
"names": ["Message_exports", "Message_default", "defaultImport", "defaultImport", "defaultImport", "Message_default"]
|
|
7
7
|
}
|
package/RemoteIcon.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import IconContext from '@splunk/visualization-context/IconContext';
|
|
3
|
+
interface RemoteIconProps {
|
|
4
|
+
alt?: string;
|
|
5
|
+
iconURL?: string;
|
|
6
|
+
color?: string;
|
|
7
|
+
width?: number | string;
|
|
8
|
+
height?: number | string;
|
|
9
|
+
opacity?: number;
|
|
10
|
+
onIconClick?: (event: React.MouseEvent<HTMLDivElement>) => void;
|
|
11
|
+
}
|
|
12
|
+
interface RemoteIconState {
|
|
13
|
+
iconDataURI: string | null;
|
|
14
|
+
}
|
|
15
|
+
declare class RemoteIcon extends React.PureComponent<RemoteIconProps, RemoteIconState> {
|
|
16
|
+
static readonly contextType: IconContext;
|
|
17
|
+
static readonly BASIC_SHAPES: string[];
|
|
18
|
+
constructor(props: RemoteIconProps);
|
|
19
|
+
UNSAFE_componentWillMount(): void;
|
|
20
|
+
componentDidUpdate(prevProps: any): void;
|
|
21
|
+
/**
|
|
22
|
+
* Check if the iconURL is a registry URL/dataURI/direct URL and fetch from the registry when required
|
|
23
|
+
* @param {String} iconURL
|
|
24
|
+
* @param {String} color
|
|
25
|
+
*/
|
|
26
|
+
getIcon(iconURL: any, color: any): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* check if icon is a registry url
|
|
29
|
+
* @param {String} src
|
|
30
|
+
*/
|
|
31
|
+
isRegistryURL(src?: string): boolean;
|
|
32
|
+
colorIcon(dataURI: any, color: any): void;
|
|
33
|
+
render(): React.JSX.Element;
|
|
34
|
+
}
|
|
35
|
+
export default RemoteIcon;
|
package/RemoteIcon.js
CHANGED
|
@@ -7,7 +7,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
7
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
10
|
var __export = (target, all) => {
|
|
12
11
|
for (var name in all)
|
|
13
12
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -30,7 +29,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
29
|
mod
|
|
31
30
|
));
|
|
32
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
34
32
|
var __async = (__this, __arguments, generator) => {
|
|
35
33
|
return new Promise((resolve, reject) => {
|
|
36
34
|
var fulfilled = (value) => {
|
|
@@ -52,7 +50,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
52
50
|
});
|
|
53
51
|
};
|
|
54
52
|
|
|
55
|
-
// src/RemoteIcon.
|
|
53
|
+
// src/RemoteIcon.tsx
|
|
56
54
|
var RemoteIcon_exports = {};
|
|
57
55
|
__export(RemoteIcon_exports, {
|
|
58
56
|
default: () => RemoteIcon_default
|
|
@@ -68,59 +66,50 @@ var defaultImport = __toESM(require("react"));
|
|
|
68
66
|
__reExport(react_exports, require("react"));
|
|
69
67
|
var react_default = "default" in defaultImport ? defaultImport.default : defaultImport;
|
|
70
68
|
|
|
71
|
-
// esm-externals:prop-types
|
|
72
|
-
var prop_types_exports = {};
|
|
73
|
-
__export(prop_types_exports, {
|
|
74
|
-
default: () => prop_types_default
|
|
75
|
-
});
|
|
76
|
-
var defaultImport2 = __toESM(require("prop-types"));
|
|
77
|
-
__reExport(prop_types_exports, require("prop-types"));
|
|
78
|
-
var prop_types_default = "default" in defaultImport2 ? defaultImport2.default : defaultImport2;
|
|
79
|
-
|
|
80
69
|
// esm-externals:styled-components
|
|
81
70
|
var styled_components_exports = {};
|
|
82
71
|
__export(styled_components_exports, {
|
|
83
72
|
default: () => styled_components_default
|
|
84
73
|
});
|
|
85
|
-
var
|
|
74
|
+
var defaultImport2 = __toESM(require("styled-components"));
|
|
86
75
|
__reExport(styled_components_exports, require("styled-components"));
|
|
87
|
-
var styled_components_default = "default" in
|
|
76
|
+
var styled_components_default = "default" in defaultImport2 ? defaultImport2.default : defaultImport2;
|
|
88
77
|
|
|
89
78
|
// esm-externals:xmlserializer
|
|
90
79
|
var xmlserializer_exports = {};
|
|
91
80
|
__export(xmlserializer_exports, {
|
|
92
81
|
default: () => xmlserializer_default
|
|
93
82
|
});
|
|
94
|
-
var
|
|
83
|
+
var defaultImport3 = __toESM(require("xmlserializer"));
|
|
95
84
|
__reExport(xmlserializer_exports, require("xmlserializer"));
|
|
96
|
-
var xmlserializer_default = "default" in
|
|
85
|
+
var xmlserializer_default = "default" in defaultImport3 ? defaultImport3.default : defaultImport3;
|
|
97
86
|
|
|
98
87
|
// esm-externals:@splunk/ui-utils/i18n
|
|
99
88
|
var i18n_exports = {};
|
|
100
89
|
__export(i18n_exports, {
|
|
101
90
|
default: () => i18n_default
|
|
102
91
|
});
|
|
103
|
-
var
|
|
92
|
+
var defaultImport4 = __toESM(require("@splunk/ui-utils/i18n"));
|
|
104
93
|
__reExport(i18n_exports, require("@splunk/ui-utils/i18n"));
|
|
105
|
-
var i18n_default = "default" in
|
|
94
|
+
var i18n_default = "default" in defaultImport4 ? defaultImport4.default : defaultImport4;
|
|
106
95
|
|
|
107
96
|
// esm-externals:@splunk/visualization-context/IconContext
|
|
108
97
|
var IconContext_exports = {};
|
|
109
98
|
__export(IconContext_exports, {
|
|
110
99
|
default: () => IconContext_default
|
|
111
100
|
});
|
|
112
|
-
var
|
|
101
|
+
var defaultImport5 = __toESM(require("@splunk/visualization-context/IconContext"));
|
|
113
102
|
__reExport(IconContext_exports, require("@splunk/visualization-context/IconContext"));
|
|
114
|
-
var IconContext_default = "default" in
|
|
103
|
+
var IconContext_default = "default" in defaultImport5 ? defaultImport5.default : defaultImport5;
|
|
115
104
|
|
|
116
105
|
// esm-externals:lodash/isNumber
|
|
117
106
|
var isNumber_exports = {};
|
|
118
107
|
__export(isNumber_exports, {
|
|
119
108
|
default: () => isNumber_default
|
|
120
109
|
});
|
|
121
|
-
var
|
|
110
|
+
var defaultImport6 = __toESM(require("lodash/isNumber"));
|
|
122
111
|
__reExport(isNumber_exports, require("lodash/isNumber"));
|
|
123
|
-
var isNumber_default = "default" in
|
|
112
|
+
var isNumber_default = "default" in defaultImport6 ? defaultImport6.default : defaultImport6;
|
|
124
113
|
|
|
125
114
|
// src/style.js
|
|
126
115
|
var toPx = (number, defaultNumber = 0) => isNumber_default(number) ? `${number}px` : number || toPx(defaultNumber);
|
|
@@ -156,7 +145,7 @@ var b64EncodeUnicode = (str) => (
|
|
|
156
145
|
btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => String.fromCharCode(`0x${p1}`)))
|
|
157
146
|
);
|
|
158
147
|
|
|
159
|
-
// src/RemoteIcon.
|
|
148
|
+
// src/RemoteIcon.tsx
|
|
160
149
|
var IconContainer = styled_components_default.div`
|
|
161
150
|
${(props) => toDimension({ width: props.width, height: props.height })};
|
|
162
151
|
margin: auto;
|
|
@@ -234,18 +223,18 @@ var _RemoteIcon = class _RemoteIcon extends react_exports.PureComponent {
|
|
|
234
223
|
*/
|
|
235
224
|
colorIcon(dataURI, color) {
|
|
236
225
|
fetch(dataURI).then((response) => response.text()).then((text) => {
|
|
226
|
+
var _a, _b;
|
|
237
227
|
const parser = new DOMParser();
|
|
238
228
|
const xmlDoc = parser.parseFromString(text, "text/xml");
|
|
239
229
|
const svg = xmlDoc.getElementsByTagName("svg")[0];
|
|
240
230
|
const children = svg.querySelectorAll("*");
|
|
241
231
|
svg.style.color = color;
|
|
242
|
-
for (
|
|
243
|
-
const child = children[i];
|
|
232
|
+
for (const child of children) {
|
|
244
233
|
if (_RemoteIcon.BASIC_SHAPES.includes(child.tagName)) {
|
|
245
234
|
const fillAttr = child.getAttribute("fill");
|
|
246
|
-
const fillStyle = child.style
|
|
235
|
+
const fillStyle = (_a = child.style) == null ? void 0 : _a.fill;
|
|
247
236
|
const strokeAttr = child.getAttribute("stroke");
|
|
248
|
-
const strokeStyle = child.style
|
|
237
|
+
const strokeStyle = (_b = child.style) == null ? void 0 : _b.stroke;
|
|
249
238
|
if (shouldChangeFill({
|
|
250
239
|
fillAttr,
|
|
251
240
|
fillStyle,
|
|
@@ -266,7 +255,8 @@ var _RemoteIcon = class _RemoteIcon extends react_exports.PureComponent {
|
|
|
266
255
|
}
|
|
267
256
|
}
|
|
268
257
|
}
|
|
269
|
-
const
|
|
258
|
+
const s = xmlserializer_exports.serializeToString(svg);
|
|
259
|
+
const svgStr = b64EncodeUnicode(s);
|
|
270
260
|
const iconDataURI = `data:image/svg+xml;base64,${svgStr}`;
|
|
271
261
|
this.setState({ iconDataURI });
|
|
272
262
|
}).catch(() => {
|
|
@@ -275,15 +265,15 @@ var _RemoteIcon = class _RemoteIcon extends react_exports.PureComponent {
|
|
|
275
265
|
}
|
|
276
266
|
render() {
|
|
277
267
|
const { iconDataURI } = this.state;
|
|
278
|
-
const { width, height, opacity, onIconClick } = this.props;
|
|
268
|
+
const { alt = (0, i18n_exports._)("Remote Icon"), width = 100, height = 100, opacity = 1, onIconClick } = this.props;
|
|
279
269
|
if (!iconDataURI) {
|
|
280
270
|
return null;
|
|
281
271
|
}
|
|
282
|
-
return /* @__PURE__ */
|
|
272
|
+
return /* @__PURE__ */ react_exports.createElement(IconContainer, { width, height, onClick: onIconClick }, /* @__PURE__ */ react_exports.createElement(
|
|
283
273
|
ColoredIcon,
|
|
284
274
|
{
|
|
285
275
|
src: iconDataURI,
|
|
286
|
-
alt
|
|
276
|
+
alt,
|
|
287
277
|
width,
|
|
288
278
|
height,
|
|
289
279
|
opacity,
|
|
@@ -292,21 +282,8 @@ var _RemoteIcon = class _RemoteIcon extends react_exports.PureComponent {
|
|
|
292
282
|
));
|
|
293
283
|
}
|
|
294
284
|
};
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
iconURL: prop_types_default.string,
|
|
298
|
-
color: prop_types_default.string,
|
|
299
|
-
width: prop_types_default.number,
|
|
300
|
-
height: prop_types_default.number,
|
|
301
|
-
opacity: prop_types_default.number,
|
|
302
|
-
onIconClick: prop_types_default.func
|
|
303
|
-
});
|
|
304
|
-
__publicField(_RemoteIcon, "defaultProps", {
|
|
305
|
-
width: 100,
|
|
306
|
-
height: 100,
|
|
307
|
-
opacity: 1
|
|
308
|
-
});
|
|
309
|
-
__publicField(_RemoteIcon, "BASIC_SHAPES", ["path", "rect", "circle", "ellipse", "line", "polyline", "polygon"]);
|
|
285
|
+
_RemoteIcon.contextType = IconContext_default;
|
|
286
|
+
_RemoteIcon.BASIC_SHAPES = ["path", "rect", "circle", "ellipse", "line", "polyline", "polygon"];
|
|
310
287
|
var RemoteIcon = _RemoteIcon;
|
|
311
288
|
var RemoteIcon_default = RemoteIcon;
|
|
312
289
|
//# sourceMappingURL=RemoteIcon.js.map
|