@splunk/visualizations-shared 28.1.0 → 28.2.1

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.
@@ -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
- return __async(this, null, function* () {
86
- const imageRegistry = this.context;
87
- if (!imageRegistry) {
88
- error((0, i18n_exports._)("Missing Image Context"));
89
- }
90
- try {
91
- const imageData = yield imageRegistry.getByURL(url);
92
- const [mime, svgBase64] = imageData.dataURI.split("base64,");
93
- if (mime && mime.toLowerCase().indexOf("image/svg+xml") > -1) {
94
- complete(b64DecodeUnicode(svgBase64));
95
- } else {
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
  };
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(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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AG5B,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 | 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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,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
  }
@@ -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;
@@ -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 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;",
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;
@@ -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.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/RemoteIcon.tsx", "esm-externals:react", "esm-externals:styled-components", "esm-externals:xmlserializer", "esm-externals:@splunk/ui-utils/i18n", "esm-externals:@splunk/visualization-context/IconContext", "esm-externals:lodash/isNumber", "src/style.js", "src/iconUtils.js"],
4
- "sourcesContent": ["/* eslint-disable class-methods-use-this */\nimport * as React from 'react';\nimport styled from 'styled-components';\nimport * as xmlserializer from 'xmlserializer';\nimport { _ } from '@splunk/ui-utils/i18n';\nimport IconContext from '@splunk/visualization-context/IconContext';\nimport { toDimension } from './style';\nimport { shouldChangeFill, shouldChangeStroke, b64EncodeUnicode } from './iconUtils';\n\ninterface RemoteIconProps {\n alt?: string;\n iconURL?: string;\n color?: string;\n width?: number;\n height?: number;\n opacity?: number;\n onIconClick?: (event: React.MouseEvent<HTMLDivElement>) => void;\n}\n\ninterface RemoteIconState {\n iconDataURI: string | null;\n}\n\nconst IconContainer = styled.div<RemoteIconProps>`\n ${props => toDimension({ width: props.width, height: props.height })};\n margin: auto;\n cursor: ${props => (props.onClick ? 'pointer' : 'inherit')};\n`;\n\nconst ColoredIcon = styled.img<RemoteIconProps>`\n ${props => toDimension({ width: props.width, height: props.height })};\n opacity: ${props => props.opacity || 1.0};\n`;\n\nclass RemoteIcon extends React.PureComponent<RemoteIconProps, RemoteIconState> {\n static readonly contextType: IconContext = IconContext;\n\n static readonly BASIC_SHAPES = ['path', 'rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon'];\n\n constructor(props: RemoteIconProps) {\n super(props);\n this.state = { iconDataURI: null };\n }\n\n // eslint-disable-next-line camelcase\n UNSAFE_componentWillMount() {\n this.getIcon(this.props.iconURL, this.props.color);\n }\n\n componentDidUpdate(prevProps) {\n if (prevProps.iconURL !== this.props.iconURL || prevProps.color !== this.props.color) {\n this.getIcon(this.props.iconURL, this.props.color);\n }\n }\n\n /**\n * Check if the iconURL is a registry URL/dataURI/direct URL and fetch from the registry when required\n * @param {String} iconURL\n * @param {String} color\n */\n async getIcon(iconURL, color) {\n const getIconDataURI = async () => {\n if (this.isRegistryURL(iconURL)) {\n const iconRegistry: IconContext = this.context;\n if (iconRegistry) {\n try {\n const icon = (await iconRegistry.getByURL(iconURL)) as any;\n return icon.dataURI;\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(_(error));\n }\n }\n } else {\n return iconURL;\n }\n return null;\n };\n\n const iconDataURI = await getIconDataURI();\n\n if (color) {\n this.colorIcon(iconDataURI, color);\n } else {\n this.setState({ iconDataURI });\n }\n }\n\n /**\n * check if icon is a registry url\n * @param {String} src\n */\n isRegistryURL(src = '') {\n const [type] = src.split('://');\n return type !== 'http' && type !== 'https' && !src.startsWith('data:image/svg+xml;base64');\n }\n\n /*\n * Color the icon:\n * parse svg elements from the dataURI, change color style of svg, and change fill/stroke attribute/style of each svg basic shapes\n * in the svg element to currentColor. At the end, convert the modified svg back to dataURI string.\n *\n * Limitation:\n * if the svg is created with multiple pathes with different fill attributes, this method would\n * convert all pathes' fill attribute to the color prop. It may change the view of the svg icon.\n *\n * @method colorIcon\n * @params {DataURI} dataURI\n * @params {String} color e.g. 'red' || '#ffffff'\n */\n colorIcon(dataURI, color) {\n fetch(dataURI)\n .then(response => response.text())\n .then(text => {\n const parser = new DOMParser();\n const xmlDoc = parser.parseFromString(text, 'text/xml');\n const svg = xmlDoc.getElementsByTagName('svg')[0];\n const children = svg.querySelectorAll('*');\n svg.style.color = color;\n // eslint-disable-next-line no-restricted-syntax\n for (const child of children) {\n if (RemoteIcon.BASIC_SHAPES.includes(child.tagName)) {\n const fillAttr = child.getAttribute('fill');\n const fillStyle = (child as SVGElement).style?.fill;\n const strokeAttr = child.getAttribute('stroke');\n const strokeStyle = (child as SVGElement).style?.stroke;\n if (\n shouldChangeFill({\n fillAttr,\n fillStyle,\n strokeAttr,\n strokeStyle,\n })\n ) {\n (child as SVGElement).style.fill = '';\n child.setAttribute('fill', 'currentColor');\n }\n\n if (\n shouldChangeStroke({\n fillAttr,\n fillStyle,\n strokeAttr,\n strokeStyle,\n })\n ) {\n (child as SVGElement).style.stroke = '';\n child.setAttribute('stroke', 'currentColor');\n }\n }\n }\n const s = xmlserializer.serializeToString(svg);\n const svgStr = b64EncodeUnicode(s);\n const iconDataURI = `data:image/svg+xml;base64,${svgStr}`;\n this.setState({ iconDataURI });\n })\n .catch(() => {\n // eslint-disable-next-line no-console\n console.error(_('The icon cannot be colored properly.'));\n });\n }\n\n render() {\n const { iconDataURI } = this.state;\n const { alt = _('Remote Icon'), width = 100, height = 100, opacity = 1.0, onIconClick } = this.props;\n if (!iconDataURI) {\n return null;\n }\n return (\n <IconContainer width={width} height={height} onClick={onIconClick}>\n <ColoredIcon\n src={iconDataURI}\n alt={alt}\n width={width}\n height={height}\n opacity={opacity}\n referrerPolicy=\"no-referrer\"\n />\n </IconContainer>\n );\n }\n}\n\nexport default RemoteIcon;\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 \"xmlserializer\";\nexport * from \"xmlserializer\";\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", "\nimport * as defaultImport from \"@splunk/visualization-context/IconContext\";\nexport * from \"@splunk/visualization-context/IconContext\";\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", "/**\n * check if an icon is considered as remote icon\n * @param {*} icon\n */\nexport const isRemoteIcon = (icon = '') => icon.indexOf('://') > -1;\n\n/**\n * check if an icon is a dataURI\n * @param {*} icon\n */\nexport const isDataURI = (icon = '') => icon.startsWith('data:image/svg+xml;base64');\n\n/*\n * check whether need update fill for svg children elements\n * @params {Object} style\n * @params {String} style.fillAttr <path fill=\"red\" .../>\n * @params {String} style.fillStyle. <path style=\"fill: red;\" />\n * @params {String} style.strokeAttr. <path stroke=\"red\" .../>\n * @params {String} style.strokeStyle <path style=\"stroke: red;\" .../>\n * @returns {Boolean} true means need\n * remove fill style and change the fill attribute <path fill=\"currentColor\" />\n */\nexport const shouldChangeFill = ({ fillAttr, fillStyle, strokeAttr, strokeStyle }) => {\n const noneFillAttr = !!fillAttr && (fillAttr === 'none' || fillAttr === 'transparent');\n const noneFillStyle = !!fillStyle && (fillStyle === 'none' || fillStyle === 'transparent');\n const noFillHasStroke = !fillAttr && !fillStyle && (!!strokeAttr || !!strokeStyle);\n return !(noneFillAttr || noneFillStyle || noFillHasStroke);\n};\n\n/*\n * check whether need update stroke for svg children elements\n * @params {Object} style\n * @params {String} style.fillAttr <path fill=\"red\" .../>\n * @params {String} style.fillStyle. <path style=\"fill: red;\" />\n * @params {String} style.strokeAttr. <path stroke=\"red\" .../>\n * @params {String} style.strokeStyle <path style=\"stroke: red;\" .../>\n * @returns {Boolean} true means need\n * remove stroke style and change the stroke attribute <path stroke=\"currentColor\" />\n */\nexport const shouldChangeStroke = ({ fillAttr, fillStyle, strokeAttr, strokeStyle }) => {\n const noneStrokeAttr = !!strokeAttr && (strokeAttr === 'none' || strokeAttr === 'transparent');\n const noneStrokeStyle = !!strokeStyle && (strokeStyle === 'none' || strokeStyle === 'transparent');\n const hasFill = !!fillAttr || !!fillStyle;\n const noStroke = !strokeAttr && !strokeStyle;\n return !(noneStrokeAttr || noneStrokeStyle || hasFill || noStroke);\n};\n\n/*\n * base64 encoding\n * @param {String} str\n * @return {Base64} string using based-64 encoding\n */\nexport const b64EncodeUnicode = str =>\n // first we use encodeURIComponent to get percent-encoded UTF-8,\n // then we convert the percent encodings into raw bytes which\n // can be fed into btoa.\n btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => String.fromCharCode(`0x${p1}`)));\n"],
4
+ "sourcesContent": ["/* eslint-disable class-methods-use-this */\nimport * as React from 'react';\nimport styled from 'styled-components';\nimport * as xmlserializer from 'xmlserializer';\nimport { _ } from '@splunk/ui-utils/i18n';\nimport IconContext from '@splunk/visualization-context/IconContext';\nimport { toDimension } from './style';\nimport { shouldChangeFill, shouldChangeStroke, b64EncodeUnicode } from './iconUtils';\n\ninterface RemoteIconProps {\n alt?: string;\n iconURL?: string;\n color?: string;\n width?: number | string;\n height?: number | string;\n opacity?: number;\n onIconClick?: (event: React.MouseEvent<HTMLDivElement>) => void;\n}\n\ninterface RemoteIconState {\n iconDataURI: string | null;\n}\n\nconst IconContainer = styled.div<RemoteIconProps>`\n ${props => toDimension({ width: props.width, height: props.height })};\n margin: auto;\n cursor: ${props => (props.onClick ? 'pointer' : 'inherit')};\n`;\n\nconst ColoredIcon = styled.img<RemoteIconProps>`\n ${props => toDimension({ width: props.width, height: props.height })};\n opacity: ${props => props.opacity || 1.0};\n`;\n\nclass RemoteIcon extends React.PureComponent<RemoteIconProps, RemoteIconState> {\n static readonly contextType: IconContext = IconContext;\n\n static readonly BASIC_SHAPES = ['path', 'rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon'];\n\n constructor(props: RemoteIconProps) {\n super(props);\n this.state = { iconDataURI: null };\n }\n\n // eslint-disable-next-line camelcase\n UNSAFE_componentWillMount() {\n this.getIcon(this.props.iconURL, this.props.color);\n }\n\n componentDidUpdate(prevProps) {\n if (prevProps.iconURL !== this.props.iconURL || prevProps.color !== this.props.color) {\n this.getIcon(this.props.iconURL, this.props.color);\n }\n }\n\n /**\n * Check if the iconURL is a registry URL/dataURI/direct URL and fetch from the registry when required\n * @param {String} iconURL\n * @param {String} color\n */\n async getIcon(iconURL, color) {\n const getIconDataURI = async () => {\n if (this.isRegistryURL(iconURL)) {\n const iconRegistry: IconContext = this.context;\n if (iconRegistry) {\n try {\n const icon = (await iconRegistry.getByURL(iconURL)) as any;\n return icon.dataURI;\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(_(error));\n }\n }\n } else {\n return iconURL;\n }\n return null;\n };\n\n const iconDataURI = await getIconDataURI();\n\n if (color) {\n this.colorIcon(iconDataURI, color);\n } else {\n this.setState({ iconDataURI });\n }\n }\n\n /**\n * check if icon is a registry url\n * @param {String} src\n */\n isRegistryURL(src = '') {\n const [type] = src.split('://');\n return type !== 'http' && type !== 'https' && !src.startsWith('data:image/svg+xml;base64');\n }\n\n /*\n * Color the icon:\n * parse svg elements from the dataURI, change color style of svg, and change fill/stroke attribute/style of each svg basic shapes\n * in the svg element to currentColor. At the end, convert the modified svg back to dataURI string.\n *\n * Limitation:\n * if the svg is created with multiple pathes with different fill attributes, this method would\n * convert all pathes' fill attribute to the color prop. It may change the view of the svg icon.\n *\n * @method colorIcon\n * @params {DataURI} dataURI\n * @params {String} color e.g. 'red' || '#ffffff'\n */\n colorIcon(dataURI, color) {\n fetch(dataURI)\n .then(response => response.text())\n .then(text => {\n const parser = new DOMParser();\n const xmlDoc = parser.parseFromString(text, 'text/xml');\n const svg = xmlDoc.getElementsByTagName('svg')[0];\n const children = svg.querySelectorAll('*');\n svg.style.color = color;\n // eslint-disable-next-line no-restricted-syntax\n for (const child of children) {\n if (RemoteIcon.BASIC_SHAPES.includes(child.tagName)) {\n const fillAttr = child.getAttribute('fill');\n const fillStyle = (child as SVGElement).style?.fill;\n const strokeAttr = child.getAttribute('stroke');\n const strokeStyle = (child as SVGElement).style?.stroke;\n if (\n shouldChangeFill({\n fillAttr,\n fillStyle,\n strokeAttr,\n strokeStyle,\n })\n ) {\n (child as SVGElement).style.fill = '';\n child.setAttribute('fill', 'currentColor');\n }\n\n if (\n shouldChangeStroke({\n fillAttr,\n fillStyle,\n strokeAttr,\n strokeStyle,\n })\n ) {\n (child as SVGElement).style.stroke = '';\n child.setAttribute('stroke', 'currentColor');\n }\n }\n }\n const s = xmlserializer.serializeToString(svg);\n const svgStr = b64EncodeUnicode(s);\n const iconDataURI = `data:image/svg+xml;base64,${svgStr}`;\n this.setState({ iconDataURI });\n })\n .catch(() => {\n // eslint-disable-next-line no-console\n console.error(_('The icon cannot be colored properly.'));\n });\n }\n\n render() {\n const { iconDataURI } = this.state;\n const { alt = _('Remote Icon'), width = 100, height = 100, opacity = 1.0, onIconClick } = this.props;\n if (!iconDataURI) {\n return null;\n }\n return (\n <IconContainer width={width} height={height} onClick={onIconClick}>\n <ColoredIcon\n src={iconDataURI}\n alt={alt}\n width={width}\n height={height}\n opacity={opacity}\n referrerPolicy=\"no-referrer\"\n />\n </IconContainer>\n );\n }\n}\n\nexport default RemoteIcon;\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 \"xmlserializer\";\nexport * from \"xmlserializer\";\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", "\nimport * as defaultImport from \"@splunk/visualization-context/IconContext\";\nexport * from \"@splunk/visualization-context/IconContext\";\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", "/**\n * check if an icon is considered as remote icon\n * @param {*} icon\n */\nexport const isRemoteIcon = (icon = '') => icon.indexOf('://') > -1;\n\n/**\n * check if an icon is a dataURI\n * @param {*} icon\n */\nexport const isDataURI = (icon = '') => icon.startsWith('data:image/svg+xml;base64');\n\n/*\n * check whether need update fill for svg children elements\n * @params {Object} style\n * @params {String} style.fillAttr <path fill=\"red\" .../>\n * @params {String} style.fillStyle. <path style=\"fill: red;\" />\n * @params {String} style.strokeAttr. <path stroke=\"red\" .../>\n * @params {String} style.strokeStyle <path style=\"stroke: red;\" .../>\n * @returns {Boolean} true means need\n * remove fill style and change the fill attribute <path fill=\"currentColor\" />\n */\nexport const shouldChangeFill = ({ fillAttr, fillStyle, strokeAttr, strokeStyle }) => {\n const noneFillAttr = !!fillAttr && (fillAttr === 'none' || fillAttr === 'transparent');\n const noneFillStyle = !!fillStyle && (fillStyle === 'none' || fillStyle === 'transparent');\n const noFillHasStroke = !fillAttr && !fillStyle && (!!strokeAttr || !!strokeStyle);\n return !(noneFillAttr || noneFillStyle || noFillHasStroke);\n};\n\n/*\n * check whether need update stroke for svg children elements\n * @params {Object} style\n * @params {String} style.fillAttr <path fill=\"red\" .../>\n * @params {String} style.fillStyle. <path style=\"fill: red;\" />\n * @params {String} style.strokeAttr. <path stroke=\"red\" .../>\n * @params {String} style.strokeStyle <path style=\"stroke: red;\" .../>\n * @returns {Boolean} true means need\n * remove stroke style and change the stroke attribute <path stroke=\"currentColor\" />\n */\nexport const shouldChangeStroke = ({ fillAttr, fillStyle, strokeAttr, strokeStyle }) => {\n const noneStrokeAttr = !!strokeAttr && (strokeAttr === 'none' || strokeAttr === 'transparent');\n const noneStrokeStyle = !!strokeStyle && (strokeStyle === 'none' || strokeStyle === 'transparent');\n const hasFill = !!fillAttr || !!fillStyle;\n const noStroke = !strokeAttr && !strokeStyle;\n return !(noneStrokeAttr || noneStrokeStyle || hasFill || noStroke);\n};\n\n/*\n * base64 encoding\n * @param {String} str\n * @return {Base64} string using based-64 encoding\n */\nexport const b64EncodeUnicode = str =>\n // first we use encodeURIComponent to get percent-encoded UTF-8,\n // then we convert the percent encodings into raw bytes which\n // can be fed into btoa.\n btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => String.fromCharCode(`0x${p1}`)));\n"],
5
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,sCAAc;AACd,IAAO,4BAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBA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OAAO;AACnC,kBAAM,aAAa,QAAQ,cAAc;AAAA,UAC7C;AAEA,cACI,mBAAmB;AAAA,YACf;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACJ,CAAC,GACH;AACE,YAAC,MAAqB,MAAM,SAAS;AACrC,kBAAM,aAAa,UAAU,cAAc;AAAA,UAC/C;AAAA,QACJ;AAAA,MACJ;AACA,YAAM,IAAkB,wCAAkB,GAAG;AAC7C,YAAM,SAAS,iBAAiB,CAAC;AACjC,YAAM,cAAc,6BAA6B,MAAM;AACvD,WAAK,SAAS,EAAE,YAAY,CAAC;AAAA,IACjC,CAAC,EACA,MAAM,MAAM;AAET,cAAQ,UAAM,gBAAE,sCAAsC,CAAC;AAAA,IAC3D,CAAC;AAAA,EACT;AAAA,EAEA,SAAS;AACL,UAAM,EAAE,YAAY,IAAI,KAAK;AAC7B,UAAM,EAAE,UAAM,gBAAE,aAAa,GAAG,QAAQ,KAAK,SAAS,KAAK,UAAU,GAAK,YAAY,IAAI,KAAK;AAC/F,QAAI,CAAC,aAAa;AACd,aAAO;AAAA,IACX;AACA,WACI,4CAAC,iBAAc,OAAc,QAAgB,SAAS,eAClD;AAAA,MAAC;AAAA;AAAA,QACG,KAAK;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,gBAAe;AAAA;AAAA,IACnB,CACJ;AAAA,EAER;AACJ;AAnJM,YACc,cAA2B;AADzC,YAGc,eAAe,CAAC,QAAQ,QAAQ,UAAU,WAAW,QAAQ,YAAY,SAAS;AAHtG,IAAM,aAAN;AAqJA,IAAO,qBAAQ;",
6
6
  "names": ["defaultImport", "defaultImport", "defaultImport", "defaultImport", "defaultImport"]
7
7
  }
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ import ImageContext from '@splunk/visualization-context/ImageContext';
3
+ /**
4
+ * check if an image is considered as remote image
5
+ * @param {*} src
6
+ */
7
+ export declare const isRemoteImage: (src?: string) => boolean;
8
+ interface RemoteImageProps {
9
+ imageURL: string;
10
+ width?: number | string;
11
+ height?: number | string;
12
+ preserveAspectRatio: boolean;
13
+ title: string;
14
+ }
15
+ interface RemoteImageState {
16
+ preserveAspectRatio: boolean;
17
+ imageDataURI: string | null;
18
+ }
19
+ declare class RemoteImage extends React.PureComponent<RemoteImageProps, RemoteImageState> {
20
+ static readonly contextType: ImageContext;
21
+ constructor(props: any);
22
+ componentDidMount(): void;
23
+ componentDidUpdate(prevProps: any): void;
24
+ getImage(imageURL: any): Promise<void>;
25
+ render(): React.JSX.Element;
26
+ }
27
+ export default RemoteImage;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/RemoteImage.tsx", "esm-externals:react", "esm-externals:styled-components", "esm-externals:lodash", "esm-externals:@splunk/ui-utils/i18n", "esm-externals:@splunk/visualization-context/ImageContext", "esm-externals:lodash/isNumber", "src/style.js"],
4
- "sourcesContent": ["import * as React from 'react';\nimport styled from 'styled-components';\nimport { pick } from 'lodash';\nimport { _ } from '@splunk/ui-utils/i18n';\nimport ImageContext from '@splunk/visualization-context/ImageContext';\nimport { toDimension } from './style';\n\n/**\n * check if an image is considered as remote image\n * @param {*} src\n */\nexport const isRemoteImage = (src = '') => {\n const [type] = src.split('://');\n return src.indexOf('://') > -1 && type !== 'http' && type !== 'https';\n};\n\ninterface RemoteImageProps {\n imageURL: string;\n width: number;\n height: number;\n preserveAspectRatio: boolean;\n title: string;\n}\n\ninterface RemoteImageState {\n preserveAspectRatio: boolean;\n imageDataURI: string | null;\n}\n\ninterface ImageProps {\n shouldPreserveAspectRatio: boolean;\n width: number;\n height: number;\n}\n\nconst toImageDimensions = props => {\n if (props.shouldPreserveAspectRatio) {\n return `\n max-width: 100%;\n max-height: 100%;\n width: auto;\n height: auto;\n `;\n }\n return toDimension(pick(props, ['width', 'height']));\n};\n\nconst Image = styled.img<ImageProps>`\n display: block;\n ${props => toImageDimensions(props)};\n`;\n\nclass RemoteImage extends React.PureComponent<RemoteImageProps, RemoteImageState> {\n static readonly contextType: ImageContext = ImageContext;\n\n constructor(props) {\n super(props);\n this.state = {\n imageDataURI: null,\n preserveAspectRatio: Boolean(props.preserveAspectRatio),\n };\n }\n\n componentDidMount() {\n this.getImage(this.props.imageURL);\n }\n\n componentDidUpdate(prevProps) {\n if (prevProps.imageURL !== this.props.imageURL) {\n this.getImage(this.props.imageURL);\n }\n if (prevProps.preserveAspectRatio !== this.props.preserveAspectRatio) {\n // eslint-disable-next-line react/no-did-update-set-state\n this.setState({\n preserveAspectRatio: this.props.preserveAspectRatio,\n });\n }\n }\n\n async getImage(imageURL) {\n const imageRegistry: ImageContext = this.context;\n if (imageRegistry) {\n try {\n const image = await imageRegistry.getByURL(imageURL);\n this.setState({ imageDataURI: image.dataURI });\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(error);\n }\n }\n }\n\n render() {\n const { imageDataURI } = this.state;\n const { width, height, title } = this.props;\n\n if (!imageDataURI) {\n return null;\n }\n return (\n <Image\n src={imageDataURI}\n shouldPreserveAspectRatio={this.state.preserveAspectRatio}\n width={width}\n height={height}\n alt={_(title)}\n onError={e => {\n (e.target as HTMLImageElement).alt = _('Image not found');\n }}\n />\n );\n }\n}\n\nexport default RemoteImage;\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 \"lodash\";\nexport * from \"lodash\";\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", "\nimport * as defaultImport from \"@splunk/visualization-context/ImageContext\";\nexport * from \"@splunk/visualization-context/ImageContext\";\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"],
4
+ "sourcesContent": ["import * as React from 'react';\nimport styled from 'styled-components';\nimport { pick } from 'lodash';\nimport { _ } from '@splunk/ui-utils/i18n';\nimport ImageContext from '@splunk/visualization-context/ImageContext';\nimport { toDimension } from './style';\n\n/**\n * check if an image is considered as remote image\n * @param {*} src\n */\nexport const isRemoteImage = (src = '') => {\n const [type] = src.split('://');\n return src.indexOf('://') > -1 && type !== 'http' && type !== 'https';\n};\n\ninterface RemoteImageProps {\n imageURL: string;\n width?: number | string;\n height?: number | string;\n preserveAspectRatio: boolean;\n title: string;\n}\n\ninterface RemoteImageState {\n preserveAspectRatio: boolean;\n imageDataURI: string | null;\n}\n\ninterface ImageProps {\n shouldPreserveAspectRatio: boolean;\n width: number | string;\n height: number | string;\n}\n\nconst toImageDimensions = props => {\n if (props.shouldPreserveAspectRatio) {\n return `\n max-width: 100%;\n max-height: 100%;\n width: auto;\n height: auto;\n `;\n }\n return toDimension(pick(props, ['width', 'height']));\n};\n\nconst Image = styled.img<ImageProps>`\n display: block;\n ${props => toImageDimensions(props)};\n`;\n\nclass RemoteImage extends React.PureComponent<RemoteImageProps, RemoteImageState> {\n static readonly contextType: ImageContext = ImageContext;\n\n constructor(props) {\n super(props);\n this.state = {\n imageDataURI: null,\n preserveAspectRatio: Boolean(props.preserveAspectRatio),\n };\n }\n\n componentDidMount() {\n this.getImage(this.props.imageURL);\n }\n\n componentDidUpdate(prevProps) {\n if (prevProps.imageURL !== this.props.imageURL) {\n this.getImage(this.props.imageURL);\n }\n if (prevProps.preserveAspectRatio !== this.props.preserveAspectRatio) {\n // eslint-disable-next-line react/no-did-update-set-state\n this.setState({\n preserveAspectRatio: this.props.preserveAspectRatio,\n });\n }\n }\n\n async getImage(imageURL) {\n const imageRegistry: ImageContext = this.context;\n if (imageRegistry) {\n try {\n const image = await imageRegistry.getByURL(imageURL);\n this.setState({ imageDataURI: image.dataURI });\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(error);\n }\n }\n }\n\n render() {\n const { imageDataURI } = this.state;\n const { width, height, title } = this.props;\n\n if (!imageDataURI) {\n return null;\n }\n return (\n <Image\n src={imageDataURI}\n shouldPreserveAspectRatio={this.state.preserveAspectRatio}\n width={width}\n height={height}\n alt={_(title)}\n onError={e => {\n (e.target as HTMLImageElement).alt = _('Image not found');\n }}\n />\n );\n }\n}\n\nexport default RemoteImage;\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 \"lodash\";\nexport * from \"lodash\";\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", "\nimport * as defaultImport from \"@splunk/visualization-context/ImageContext\";\nexport * from \"@splunk/visualization-context/ImageContext\";\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
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;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,sCAAc;AACd,IAAO,4BAAS,aAAaA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Import", "defaultImport"]
7
7
  }
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Validates every property in the key and return
4
+ * only valid keys
5
+ *
6
+ * @export
7
+ * @template T
8
+ * @param {T} props
9
+ * @returns {Partial<T>}
10
+ */
11
+ export declare function sanitize<T extends Record<string, any>>(props: T): Partial<T>;
12
+ /**
13
+ * Helper HOC which will sanitize invalid props
14
+ *
15
+ * @export
16
+ * @param {React.ComponentType} WrappedComponent
17
+ * @returns {React.ComponentType}
18
+ */
19
+ export declare function withSanitizedProps<T>(WrappedComponent: React.ComponentType<T>): React.ComponentType<Partial<T>>;
@@ -0,0 +1,23 @@
1
+ import * as React from 'react';
2
+ interface SizeAwareWrapperProps {
3
+ onResize: (width: number, height: number) => void;
4
+ width?: number | string;
5
+ height?: number | string;
6
+ }
7
+ declare class SizeAwareWrapper extends React.PureComponent<SizeAwareWrapperProps, null> {
8
+ ro: ResizeObserver | {
9
+ observe(): void;
10
+ unobserve(): void;
11
+ };
12
+ el: HTMLDivElement;
13
+ componentDidMount(): void;
14
+ componentWillUnmount(): void;
15
+ getElement: () => HTMLElement;
16
+ getResizeObserver(): ResizeObserver | {
17
+ observe(): void;
18
+ unobserve(): void;
19
+ };
20
+ handleResize: (entries: any) => void;
21
+ render(): React.JSX.Element;
22
+ }
23
+ export default SizeAwareWrapper;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/SizeAwareWrapper.tsx", "esm-externals:react", "esm-externals:lodash"],
4
- "sourcesContent": ["import * as React from 'react';\nimport { noop } from 'lodash';\n\nconst styles: React.CSSProperties = {\n position: 'absolute',\n width: 0,\n height: 0,\n visibility: 'hidden',\n display: 'none',\n};\n\ninterface SizeAwareWrapperProps {\n onResize: (width: number, height: number) => void;\n // This was to use width and height as props and then check to see if the values have changed inside the handleResize function\n // Some components need a double render to 'settle' and are using this so no check is needed.\n // However until that is fixed unit tests rely on these props so keeping as optional.\n // width?: number | string;\n // height?: number | string;\n}\n\nclass SizeAwareWrapper extends React.PureComponent<SizeAwareWrapperProps, null> {\n ro: ResizeObserver | { observe(): void; unobserve(): void };\n\n el: HTMLDivElement;\n\n componentDidMount() {\n const resizableElement = this.getElement();\n if (resizableElement) {\n this.ro = this.getResizeObserver();\n this.ro.observe(resizableElement);\n }\n }\n\n componentWillUnmount() {\n const resizableElement = this.getElement();\n if (resizableElement && this.ro) {\n this.ro.unobserve(resizableElement);\n }\n }\n\n getElement = () => {\n const parentElement = this.el && this.el.parentElement;\n return parentElement;\n };\n\n getResizeObserver() {\n if (typeof ResizeObserver !== 'function') {\n return {\n observe() {},\n unobserve() {},\n };\n }\n return new ResizeObserver(this.handleResize);\n }\n\n handleResize = entries => {\n const { onResize = noop } = this.props;\n entries.forEach(entry => {\n const { width, height } = entry.contentRect;\n onResize(width, height);\n });\n };\n\n render() {\n return (\n <div\n key=\"resize-detector\"\n style={styles}\n ref={el => {\n this.el = el;\n }}\n />\n );\n }\n}\n\nexport default SizeAwareWrapper;\n", "\nimport * as defaultImport from \"react\";\nexport * from \"react\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"lodash\";\nexport * from \"lodash\";\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,2BAAc;AACd,IAAO,iBAAS,aAAaA,iBAA8B,yBAAUA;;;AFArE,IAAM,SAA8B;AAAA,EAChC,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,SAAS;AACb;AAWA,IAAM,mBAAN,cAAqC,4BAA2C;AAAA,EAAhF;AAAA;AAoBI,sBAAa,MAAM;AACf,YAAM,gBAAgB,KAAK,MAAM,KAAK,GAAG;AACzC,aAAO;AAAA,IACX;AAYA,wBAAe,aAAW;AACtB,YAAM,EAAE,WAAW,oBAAK,IAAI,KAAK;AACjC,cAAQ,QAAQ,WAAS;AACrB,cAAM,EAAE,OAAO,OAAO,IAAI,MAAM;AAChC,iBAAS,OAAO,MAAM;AAAA,MAC1B,CAAC;AAAA,IACL;AAAA;AAAA,EApCA,oBAAoB;AAChB,UAAM,mBAAmB,KAAK,WAAW;AACzC,QAAI,kBAAkB;AAClB,WAAK,KAAK,KAAK,kBAAkB;AACjC,WAAK,GAAG,QAAQ,gBAAgB;AAAA,IACpC;AAAA,EACJ;AAAA,EAEA,uBAAuB;AACnB,UAAM,mBAAmB,KAAK,WAAW;AACzC,QAAI,oBAAoB,KAAK,IAAI;AAC7B,WAAK,GAAG,UAAU,gBAAgB;AAAA,IACtC;AAAA,EACJ;AAAA,EAOA,oBAAoB;AAChB,QAAI,OAAO,mBAAmB,YAAY;AACtC,aAAO;AAAA,QACH,UAAU;AAAA,QAAC;AAAA,QACX,YAAY;AAAA,QAAC;AAAA,MACjB;AAAA,IACJ;AACA,WAAO,IAAI,eAAe,KAAK,YAAY;AAAA,EAC/C;AAAA,EAUA,SAAS;AACL,WACI;AAAA,MAAC;AAAA;AAAA,QACG,KAAI;AAAA,QACJ,OAAO;AAAA,QACP,KAAK,QAAM;AACP,eAAK,KAAK;AAAA,QACd;AAAA;AAAA,IACJ;AAAA,EAER;AACJ;AAEA,IAAO,2BAAQ;",
4
+ "sourcesContent": ["import * as React from 'react';\nimport { noop } from 'lodash';\n\nconst styles: React.CSSProperties = {\n position: 'absolute',\n width: 0,\n height: 0,\n visibility: 'hidden',\n display: 'none',\n};\n\ninterface SizeAwareWrapperProps {\n onResize: (width: number, height: number) => void;\n // This was to use width and height as props and then check to see if the values have changed inside the handleResize function\n // Some components need a double render to 'settle' and are using this so no check is needed.\n // However until that is fixed unit tests rely on these props so keeping as optional.\n // eslint-disable-next-line\n width?: number | string;\n // eslint-disable-next-line\n height?: number | string;\n}\n\nclass SizeAwareWrapper extends React.PureComponent<SizeAwareWrapperProps, null> {\n ro: ResizeObserver | { observe(): void; unobserve(): void };\n\n el: HTMLDivElement;\n\n componentDidMount() {\n const resizableElement = this.getElement();\n if (resizableElement) {\n this.ro = this.getResizeObserver();\n this.ro.observe(resizableElement);\n }\n }\n\n componentWillUnmount() {\n const resizableElement = this.getElement();\n if (resizableElement && this.ro) {\n this.ro.unobserve(resizableElement);\n }\n }\n\n getElement = () => {\n const parentElement = this.el && this.el.parentElement;\n return parentElement;\n };\n\n getResizeObserver() {\n if (typeof ResizeObserver !== 'function') {\n return {\n observe() {},\n unobserve() {},\n };\n }\n return new ResizeObserver(this.handleResize);\n }\n\n handleResize = entries => {\n const { onResize = noop } = this.props;\n entries.forEach(entry => {\n const { width, height } = entry.contentRect;\n onResize(width, height);\n });\n };\n\n render() {\n return (\n <div\n key=\"resize-detector\"\n style={styles}\n ref={el => {\n this.el = el;\n }}\n />\n );\n }\n}\n\nexport default SizeAwareWrapper;\n", "\nimport * as defaultImport from \"react\";\nexport * from \"react\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"lodash\";\nexport * from \"lodash\";\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,2BAAc;AACd,IAAO,iBAAS,aAAaA,iBAA8B,yBAAUA;;;AFArE,IAAM,SAA8B;AAAA,EAChC,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,SAAS;AACb;AAaA,IAAM,mBAAN,cAAqC,4BAA2C;AAAA,EAAhF;AAAA;AAoBI,sBAAa,MAAM;AACf,YAAM,gBAAgB,KAAK,MAAM,KAAK,GAAG;AACzC,aAAO;AAAA,IACX;AAYA,wBAAe,aAAW;AACtB,YAAM,EAAE,WAAW,oBAAK,IAAI,KAAK;AACjC,cAAQ,QAAQ,WAAS;AACrB,cAAM,EAAE,OAAO,OAAO,IAAI,MAAM;AAChC,iBAAS,OAAO,MAAM;AAAA,MAC1B,CAAC;AAAA,IACL;AAAA;AAAA,EApCA,oBAAoB;AAChB,UAAM,mBAAmB,KAAK,WAAW;AACzC,QAAI,kBAAkB;AAClB,WAAK,KAAK,KAAK,kBAAkB;AACjC,WAAK,GAAG,QAAQ,gBAAgB;AAAA,IACpC;AAAA,EACJ;AAAA,EAEA,uBAAuB;AACnB,UAAM,mBAAmB,KAAK,WAAW;AACzC,QAAI,oBAAoB,KAAK,IAAI;AAC7B,WAAK,GAAG,UAAU,gBAAgB;AAAA,IACtC;AAAA,EACJ;AAAA,EAOA,oBAAoB;AAChB,QAAI,OAAO,mBAAmB,YAAY;AACtC,aAAO;AAAA,QACH,UAAU;AAAA,QAAC;AAAA,QACX,YAAY;AAAA,QAAC;AAAA,MACjB;AAAA,IACJ;AACA,WAAO,IAAI,eAAe,KAAK,YAAY;AAAA,EAC/C;AAAA,EAUA,SAAS;AACL,WACI;AAAA,MAAC;AAAA;AAAA,QACG,KAAI;AAAA,QACJ,OAAO;AAAA,QACP,KAAK,QAAM;AACP,eAAK,KAAK;AAAA,QACd;AAAA;AAAA,IACJ;AAAA,EAER;AACJ;AAEA,IAAO,2BAAQ;",
6
6
  "names": ["defaultImport"]
7
7
  }
@@ -0,0 +1,32 @@
1
+ import * as React from 'react';
2
+ interface ComponentPageProps {
3
+ createComponentURL: (componentName: string) => string;
4
+ dependsOnSplunk: boolean;
5
+ status: string;
6
+ description: string;
7
+ overviewSection: React.ReactNode;
8
+ conceptsSection: React.ReactNode;
9
+ examplesSection: React.ReactNode;
10
+ optionSection: React.ReactNode;
11
+ encodingSection: React.ReactNode;
12
+ eventSection: React.ReactNode;
13
+ themeSection: React.ReactNode;
14
+ headerOffset: number;
15
+ sourceURL: string;
16
+ title: string;
17
+ }
18
+ interface ComponentPageState {
19
+ activeSection: string;
20
+ }
21
+ declare class ComponentPage extends React.Component<ComponentPageProps, ComponentPageState> {
22
+ static currentSection: string;
23
+ bodyEl: any;
24
+ constructor(args: any);
25
+ handleBodyMount: (el: any) => void;
26
+ handleSectionChange: (e: any, { selectedTabId }: {
27
+ selectedTabId: any;
28
+ }) => void;
29
+ renderBody(): React.ReactNode;
30
+ render(): React.JSX.Element;
31
+ }
32
+ export default ComponentPage;
@@ -0,0 +1 @@
1
+ export { isColor, isArrayOfColors, sanitizeArrayOfColors, } from '@splunk/visualization-encoding/utils/colorUtils';
@@ -0,0 +1,2 @@
1
+ declare function isDynamicOption(option?: string): boolean;
2
+ export { isDynamicOption };
@@ -0,0 +1,27 @@
1
+ export declare enum DataSourceState {
2
+ NONEXISTENT = 0,
3
+ ERROR = 1,
4
+ LOADING = 2,
5
+ OK = 3
6
+ }
7
+ /**
8
+ * represents the data in a raw columnar format, resulting from a splunk
9
+ * query request.
10
+ */
11
+ export interface FieldEntry {
12
+ name: string;
13
+ type?: string;
14
+ groupby_rank?: string;
15
+ splitby_field?: string;
16
+ splitby_value?: string;
17
+ data_source?: string;
18
+ }
19
+ /**
20
+ * A utility fn to return data source state info as an object of boolean flags
21
+ * @param dataSource
22
+ */
23
+ export declare const getDataSourceStateInfo: (dataSource: any) => {
24
+ hasError: boolean;
25
+ isMissing: boolean;
26
+ isLoading: boolean;
27
+ };
package/hocUtils.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { deepMergeWithArrayPrimitiveOverrides } from '@splunk/visualization-encoding/utils/deepMergeWithArrayPrimitiveOverrides';
package/iconUtils.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export function isRemoteIcon(icon?: any): boolean;
2
+ export function isDataURI(icon?: any): any;
3
+ export function shouldChangeFill({ fillAttr, fillStyle, strokeAttr, strokeStyle }: {
4
+ fillAttr: any;
5
+ fillStyle: any;
6
+ strokeAttr: any;
7
+ strokeStyle: any;
8
+ }): boolean;
9
+ export function shouldChangeStroke({ fillAttr, fillStyle, strokeAttr, strokeStyle }: {
10
+ fillAttr: any;
11
+ fillStyle: any;
12
+ strokeAttr: any;
13
+ strokeStyle: any;
14
+ }): boolean;
15
+ export function b64EncodeUnicode(str: any): string;
package/mapUtils.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { findClosestMatchFromDefaultList } from '@splunk/visualization-encoding/utils/findClosestMatchFromDefaultList';
2
+ export type { GeoJsonDataType } from '@splunk/visualization-encoding/utils/findClosestMatchFromDefaultList';
package/package.json CHANGED
@@ -3,15 +3,15 @@
3
3
  "description": "Visualizations Shared Files",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "author": "Splunk",
6
- "version": "28.1.0",
6
+ "version": "28.2.1",
7
7
  "scripts": {
8
- "build": "viz-build --no-types",
8
+ "build": "viz-build",
9
9
  "build-storybook": "sb build -c .storybook -o .storybook-bundle",
10
10
  "clean": "yarn clean:storybook && yarn clean:esbuild && yarn clean:test-reports",
11
11
  "clean:storybook": "rm -rf .storybook-bundle",
12
12
  "clean:esbuild": "git ls-files --others -i --exclude-standard *.js *.map | xargs rm",
13
13
  "clean:test-reports": "rm -rf ./test-reports",
14
- "dev": "viz-build --no-types --watch",
14
+ "dev": "viz-build --watch",
15
15
  "storybook": "sb dev -p 9001 -c .storybook",
16
16
  "lint": "eslint src --ext \".js,.jsx,.es,.ts,.tsx\"",
17
17
  "lint:fix": "yarn run lint --fix",
@@ -28,12 +28,12 @@
28
28
  "dependencies": {
29
29
  "@loki/create-async-callback": "^0.35.1",
30
30
  "@splunk/moment": "^0.7.0",
31
- "@splunk/react-icons": "^5.1.0",
32
- "@splunk/react-ui": "^5.1.0",
33
- "@splunk/themes": "^1.2.0",
31
+ "@splunk/react-icons": "^5.3.0",
32
+ "@splunk/react-ui": "^5.3.0",
33
+ "@splunk/themes": "^1.2.1",
34
34
  "@splunk/ui-utils": "^1.10.0",
35
- "@splunk/visualization-encoding": "^28.1.0",
36
- "@splunk/visualization-schemas": "^28.1.0",
35
+ "@splunk/visualization-encoding": "^28.2.1",
36
+ "@splunk/visualization-schemas": "^28.2.1",
37
37
  "element-resize-detector": "^1.2.4",
38
38
  "lodash": "^4.17.21",
39
39
  "numeral": "^2.0.6",
@@ -41,21 +41,21 @@
41
41
  "xmlserializer": "^0.6.1"
42
42
  },
43
43
  "peerDependencies": {
44
- "@splunk/visualization-context": "^28.1.0",
44
+ "@splunk/visualization-context": "^28.2.1",
45
45
  "react": "^18.3.1",
46
46
  "react-dom": "^18.3.1",
47
47
  "styled-components": "^5.3.10"
48
48
  },
49
49
  "devDependencies": {
50
- "@splunk/react-docs": "^1.1.0",
51
- "@splunk/visualization-build-tools": "^28.1.0",
52
- "@splunk/visualization-context": "^28.1.0",
50
+ "@splunk/react-docs": "^1.3.0",
51
+ "@splunk/visualization-build-tools": "^28.2.1",
52
+ "@splunk/visualization-context": "^28.2.1",
53
53
  "@storybook/addon-actions": "^7.6.20",
54
54
  "@storybook/addons": "^7.6.20",
55
55
  "@storybook/react": "^7.6.20",
56
56
  "@storybook/react-webpack5": "^7.6.20",
57
57
  "@testing-library/dom": "^10.4.1",
58
- "@testing-library/react": "^16.2.0",
58
+ "@testing-library/react": "^16.3.0",
59
59
  "jest-canvas-mock": "^2.5.2",
60
60
  "jest-styled-components": "^7.2.0",
61
61
  "loki": "^0.35.1",
@@ -0,0 +1,2 @@
1
+ declare const previewVizMessage = "\u26A0\uFE0F This is a preview of a new visualization component. Minor updates and bug fixes should be expected.";
2
+ export default previewVizMessage;
@@ -0,0 +1 @@
1
+ export { schemaDraft07 as default, createTestSchema, TOKEN_PATTERN, rgbColorPattern, rgbaColorPattern, colorPattern, colorPatternWithRGBA, COLOR_OR_TOKEN_PATTERN, COLOR_OR_TOKEN_PATTERN_WITH_RGBA, DYNAMIC_OPTIONS_DSL_PATTERN, getPattern, } from '@splunk/visualization-schemas';
package/style.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export function toPx(number: any, defaultNumber?: number): any;
2
+ export function toDimension({ width, height }: any): string;
3
+ export function arrayToCSSProp(prop: any, vals?: number[]): string;
4
+ export function toMargin(margins?: number[]): string;
5
+ export function toPadding(paddings?: number[]): string;
@@ -0,0 +1,21 @@
1
+ import { FieldEntry } from './dataSourceUtils';
2
+ export declare const CHART = "chart";
3
+ export declare const TIMECHART = "timechart";
4
+ export declare const STATS = "stats";
5
+ export declare const UNKNOWN = "unknown";
6
+ export type DataSplitMode = 'timechart' | 'chart' | 'stats' | 'unknown';
7
+ export declare const getTrellisDataSplitterMode: (fields: FieldEntry[]) => DataSplitMode;
8
+ export declare const isTimeChartCmdData: (fields: FieldEntry[]) => boolean;
9
+ export declare const isChartCmdData: (fields: FieldEntry[]) => boolean;
10
+ export declare const isStatsCmdData: (fields: FieldEntry[]) => boolean;
11
+ export declare const checkForTrellisFieldMetaInfo: (fields: FieldEntry[]) => boolean;
12
+ export declare const extractSplitByFieldsChartFields: (fields: FieldEntry[]) => string[];
13
+ export declare const extractDataSourceAggregationKeysChart: (fields: FieldEntry[]) => string[];
14
+ export declare const extractAllAggregationKeysChart: (fields: FieldEntry[]) => string[];
15
+ export declare const extractDataSourceAggregationKeysStats: (fields: FieldEntry[]) => string[];
16
+ export declare const extractSplitByFieldsForStats: (fields: FieldEntry[]) => string[];
17
+ export declare const extractSplitByFieldsForUnknown: (fields: FieldEntry[]) => string[];
18
+ export declare const getAllPossibleSplitByFields: (fields: FieldEntry[]) => {
19
+ fields: string[];
20
+ aggregations: string[];
21
+ };
package/tsconfig.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "lib": ["ES2020", "DOM"],
3
4
  "sourceMap": true,
4
5
  "module": "commonjs",
5
6
  "target": "es6",
6
7
  "jsx": "react",
7
8
  "preserveSymlinks": true,
9
+ "declaration": true,
10
+ "declarationDir": ".",
11
+ "esModuleInterop": true,
12
+ "allowJs": true,
13
+ "checkJs": false,
14
+ "skipLibCheck": true
8
15
  },
9
- "include": [
10
- "**/*.ts",
11
- "**/*.tsx"
12
- ],
13
- "exclude": [
14
- "node_modules/**/*",
15
- "./src/**/*.test.ts"
16
- ]
16
+ "include": ["src/*.ts", "src/*.tsx"],
17
+ "exclude": ["./src/**/*.test.ts"]
17
18
  }