@splunk/visualizations-shared 28.7.0 → 28.9.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/Downloader.js +3 -6
- package/Downloader.js.map +2 -2
- package/FileDownloader.js.map +2 -2
- package/Message.js +17 -2
- package/Message.js.map +4 -4
- package/RemoteIcon.js +1 -3
- package/RemoteIcon.js.map +2 -2
- package/RemoteImage.js +0 -1
- package/RemoteImage.js.map +2 -2
- package/SanitizeProps.js.map +2 -2
- package/SizeAwareWrapper.js.map +2 -2
- package/VisualizationDocPage.d.ts +0 -1
- package/VisualizationDocPage.js +18 -27
- package/VisualizationDocPage.js.map +2 -2
- package/console.js +10 -10
- package/console.js.map +2 -2
- package/dataSourceUtils.js.map +1 -1
- package/domUtils.js +1 -1
- package/domUtils.js.map +2 -2
- package/i18n.js +1 -1
- package/i18n.js.map +2 -2
- package/iconUtils.js +2 -2
- package/iconUtils.js.map +2 -2
- package/numberUtils.js +4 -4
- package/numberUtils.js.map +2 -2
- package/package.json +12 -12
- package/propUtils.js +2 -2
- package/propUtils.js.map +2 -2
- package/simpleXMLOptions.js +4 -6
- package/simpleXMLOptions.js.map +2 -2
- package/trellisUtils.js +2 -1
- package/trellisUtils.js.map +2 -2
package/Downloader.js
CHANGED
|
@@ -75,7 +75,7 @@ var i18n_default = "default" in defaultImport ? defaultImport.default : defaultI
|
|
|
75
75
|
var b64DecodeUnicode = (base64Data) => {
|
|
76
76
|
return decodeURIComponent(
|
|
77
77
|
atob(base64Data).split("").map((c) => {
|
|
78
|
-
const hex = `00${c.
|
|
78
|
+
const hex = `00${c.codePointAt(0).toString(16)}`.slice(-2);
|
|
79
79
|
return `%${hex}`;
|
|
80
80
|
}).join("")
|
|
81
81
|
);
|
|
@@ -105,11 +105,9 @@ var ImageRegistryFetcher = class {
|
|
|
105
105
|
};
|
|
106
106
|
var URLDownloader = class {
|
|
107
107
|
downloadWithProgress(url, complete, progress, error) {
|
|
108
|
-
fetch(url).then((response) => __async(
|
|
108
|
+
fetch(url).then((response) => __async(null, null, function* () {
|
|
109
109
|
if (!response.ok) {
|
|
110
|
-
|
|
111
|
-
console.warn(msg);
|
|
112
|
-
error(msg);
|
|
110
|
+
error(`Fetch not Ok for ${url}, status was '${response.statusText}'`);
|
|
113
111
|
return;
|
|
114
112
|
}
|
|
115
113
|
const reader = response.body.getReader();
|
|
@@ -150,7 +148,6 @@ var URLDownloader = class {
|
|
|
150
148
|
complete(svg);
|
|
151
149
|
})).catch((e) => {
|
|
152
150
|
const stringifiedError = e.toString();
|
|
153
|
-
console.error(stringifiedError);
|
|
154
151
|
if (stringifiedError.includes("Failed to fetch")) {
|
|
155
152
|
error(
|
|
156
153
|
`Cannot fetch the image "${url}" due to a cross-origin resource sharing (CORS) policy`,
|
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 | 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 const hex = `00${c.
|
|
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,YAAM,MAAM,KAAK,EAAE,
|
|
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 const hex = `00${c.codePointAt(0).toString(16)}`.slice(-2);\n return `%${hex}`;\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?.toLowerCase().includes('image/svg+xml')) {\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 error(`Fetch not Ok for ${url}, status was '${response.statusText}'`);\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 // 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 = {}; // NOSONAR - reassigned in constructor\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) /* NOSONAR typescript:S2486 - a URL parse failure is the expected signal that the input is not a URL; setting isUrl=false is the intended result */ {\n isUrl = false;\n }\n\n if (isUrl) {\n try {\n const [type = ''] = protocol.split(':');\n if (this.downloaders[type]) {\n // data, http(s), local....\n this.downloaders[type].downloadWithProgress(url, complete, progress, error);\n } else {\n // unknown type\n error(`Unsupported URL protocol '${type}' for SVG download: ${url}`);\n }\n } catch (e) {\n error(`Unexpected error downloading SVG: ${e.message}`);\n }\n } else {\n // the url might be literal content. <svg>...</svg>. This is kindof a hack where if you pass the downloader something\n // that is literal content, it will just return the content. Makes the code flow cleaner in layers above.\n complete(url);\n }\n }\n}\n", "\nimport * as defaultImport from \"@splunk/ui-utils/i18n\";\nexport * from \"@splunk/ui-utils/i18n\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AACA,oBAA+B;AAC/B,yBAAc;AACd,IAAO,eAAS,aAAa,gBAA8B,wBAAU;;;ADgB9D,IAAM,mBAAmB,CAAC,eAA+B;AAE5D,SAAO;AAAA,IACH,KAAK,UAAU,EACV,MAAM,EAAE,EACR,IAAI,CAAC,MAAsB;AACxB,YAAM,MAAM,KAAK,EAAE,YAAY,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,MAAM,EAAE;AACzD,aAAO,IAAI,G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BAAqB,KAAK,UAAU,UAAU,KAAK;AAAA,QAC9E,OAAO;AAEH,gBAAM,6BAA6B,IAAI,uBAAuB,GAAG,EAAE;AAAA,QACvE;AAAA,MACJ,SAAS,GAAG;AACR,cAAM,qCAAqC,EAAE,OAAO,EAAE;AAAA,MAC1D;AAAA,IACJ,OAAO;AAGH,eAAS,GAAG;AAAA,IAChB;AAAA,EACJ;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/FileDownloader.js.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 | 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 const hex = `00${c.charCodeAt(0).toString(16)}`.slice(-2);\n return `%${hex}`;\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?.toLowerCase().includes('image/svg+xml')) {\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 = {}; // NOSONAR - reassigned in constructor\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 const hex = `00${c.codePointAt(0).toString(16)}`.slice(-2);\n return `%${hex}`;\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?.toLowerCase().includes('image/svg+xml')) {\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 error(`Fetch not Ok for ${url}, status was '${response.statusText}'`);\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 // 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 = {}; // NOSONAR - reassigned in constructor\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) /* NOSONAR typescript:S2486 - a URL parse failure is the expected signal that the input is not a URL; setting isUrl=false is the intended result */ {\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;AAAA,EAG5B,YAAY,aAAkD;AAF9D,wBAAQ,eAAc,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,GAAuJ;AAC5J,cAAQ;AAAA,IACZ;AAEA,QAAI,OAAO;AACP,UAAI;AACA,cAAM,CAAC,OAAO,EAAE,IAAI,SAAS,MAAM,GAAG;AACtC,YAAI,KAAK,YAAY,IAAI,GAAG;AAExB,eAAK,YAAY,IAAI,EAAE,qBAAqB,KAAK,UAAU,UAAU,KAAK;AAAA,QAC9E,OAAO;AAEH,gBAAM,6BAA6B,IAAI,uBAAuB,GAAG,EAAE;AAAA,QACvE;AAAA,MACJ,SAAS,GAAG;AACR,cAAM,qCAAqC,EAAE,OAAO,EAAE;AAAA,MAC1D;AAAA,IACJ,OAAO;AAGH,eAAS,GAAG;AAAA,IAChB;AAAA,EACJ;AACJ;;;AHpKO,IAAM,iBAAiB,CAAC,UAA4C;AACvE,QAAM,CAAC,SAAS,UAAU,IAAU,uBAAiB;AACrD,QAAM,CAAC,UAAU,WAAW,IAAU,uBAA2B;AAAA,IAC7D,SAAS,eAAe,MAAM,GAAG;AAAA,IACjC,iBAAiB;AAAA,EACrB,CAAC;AACD,QAAM,CAAC,OAAO,QAAQ,IAAU,uBAAiB;AACjD,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,CAAC,QAA6B,4CAAC,aAAK,GAAI;AAAA,EAC1D,IAAI;AACJ,EAAM,wBAAU,MAAM;AAClB,UAAM,aAAa,IAAI,WAAW,MAAM,gBAAgB;AACxD,eAAW;AAAA,MACP;AAAA,MACA,cAAY,WAAW,QAAQ;AAAA;AAAA,MAC/B,CAAC,oBAA4C;AACzC,oBAAY,eAAe;AAAA,MAC/B;AAAA,MACA,CAAC,QAAsB;AACnB,iBAAS,GAAG;AAAA,MAChB;AAAA,IACJ;AAAA,EACJ,GAAG,CAAC,MAAM,kBAAkB,GAAG,CAAC;AAChC,MAAI,SAAS;AACT,WAAO,cAAc,OAAO;AAAA,EAChC;AACA,MAAI,OAAO;AACP,WAAO,YAAY,KAAK;AAAA,EAC5B;AACA,SAAO,OAAO,mBAAmB,aAAa,eAAe,QAAQ,IAAI;AAC7E;",
|
|
6
6
|
"names": ["defaultImport"]
|
|
7
7
|
}
|
package/Message.js
CHANGED
|
@@ -64,14 +64,23 @@ var defaultImport3 = __toESM(require("@splunk/react-ui/Message"));
|
|
|
64
64
|
__reExport(Message_exports, require("@splunk/react-ui/Message"));
|
|
65
65
|
var Message_default = "default" in defaultImport3 ? defaultImport3.default : defaultImport3;
|
|
66
66
|
|
|
67
|
+
// esm-externals:@splunk/themes
|
|
68
|
+
var themes_exports = {};
|
|
69
|
+
__export(themes_exports, {
|
|
70
|
+
default: () => themes_default
|
|
71
|
+
});
|
|
72
|
+
var defaultImport4 = __toESM(require("@splunk/themes"));
|
|
73
|
+
__reExport(themes_exports, require("@splunk/themes"));
|
|
74
|
+
var themes_default = "default" in defaultImport4 ? defaultImport4.default : defaultImport4;
|
|
75
|
+
|
|
67
76
|
// esm-externals:lodash/isNumber
|
|
68
77
|
var isNumber_exports = {};
|
|
69
78
|
__export(isNumber_exports, {
|
|
70
79
|
default: () => isNumber_default
|
|
71
80
|
});
|
|
72
|
-
var
|
|
81
|
+
var defaultImport5 = __toESM(require("lodash/isNumber"));
|
|
73
82
|
__reExport(isNumber_exports, require("lodash/isNumber"));
|
|
74
|
-
var isNumber_default = "default" in
|
|
83
|
+
var isNumber_default = "default" in defaultImport5 ? defaultImport5.default : defaultImport5;
|
|
75
84
|
|
|
76
85
|
// src/style.js
|
|
77
86
|
var toPx = (number, defaultNumber = 0) => isNumber_default(number) ? `${number}px` : number || toPx(defaultNumber);
|
|
@@ -92,6 +101,12 @@ var MessageContainer = styled_components_default.div`
|
|
|
92
101
|
display: flex;
|
|
93
102
|
justify-content: center;
|
|
94
103
|
align-items: center;
|
|
104
|
+
/* SUI 5's 1CD colors use oklch. Older browsers inherit this fallback when
|
|
105
|
+
they discard the unsupported color declaration on SplunkUIMessage. */
|
|
106
|
+
color: ${(0, themes_exports.pick)({
|
|
107
|
+
dark: "#fafafa",
|
|
108
|
+
light: "#2c2c2c"
|
|
109
|
+
})};
|
|
95
110
|
${(p) => toDimension({ width: p.width, height: p.height })};
|
|
96
111
|
`;
|
|
97
112
|
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));
|
package/Message.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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;;;
|
|
6
|
-
"names": ["Message_exports", "Message_default", "defaultImport", "defaultImport", "defaultImport", "Message_default"]
|
|
3
|
+
"sources": ["src/Message.tsx", "esm-externals:react", "esm-externals:styled-components", "esm-externals:@splunk/react-ui/Message", "esm-externals:@splunk/themes", "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 { pick } from '@splunk/themes';\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 /* SUI 5's 1CD colors use oklch. Older browsers inherit this fallback when\n they discard the unsupported color declaration on SplunkUIMessage. */\n color: ${pick({\n dark: '#fafafa',\n light: '#2c2c2c',\n })};\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 \"@splunk/themes\";\nexport * from \"@splunk/themes\";\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,2BAAc;AACd,IAAO,iBAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,6BAAc;AACd,IAAO,mBAAS,aAAaA,iBAA8B,yBAAUA;;;ACG9D,IAAM,OAAO,CAAC,QAAQ,gBAAgB,MACzC,iBAAS,MAAM,IAAI,GAAG,MAAM,OAAO,UAAU,KAAK,aAAa;AAM5D,IAAM,cAAc,CAAC,EAAE,OAAO,OAAO,MAAM;AAC9C,MAAI,MAAM;AACV,MAAI,OAAO;AACP,UAAM,UAAU,KAAK,KAAK,CAAC;AAAA,EAC/B;AACA,MAAI,QAAQ;AAER,UAAM,GAAG,GAAG,GAAG,QAAQ,OAAO,EAAE,WAAW,KAAK,MAAM,CAAC;AAAA,EAC3D;AACA,SAAO;AACX;;;ANjBA,IAAM,mBAAmB,0BAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAOnB,qBAAK;AAAA,EACV,MAAM;AAAA,EACN,OAAO;AACX,CAAC,CAAC;AAAA,MACA,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", "defaultImport", "Message_default"]
|
|
7
7
|
}
|
package/RemoteIcon.js
CHANGED
|
@@ -144,7 +144,7 @@ var b64EncodeUnicode = (str) => (
|
|
|
144
144
|
// first we use encodeURIComponent to get percent-encoded UTF-8,
|
|
145
145
|
// then we convert the percent encodings into raw bytes which
|
|
146
146
|
// can be fed into btoa.
|
|
147
|
-
btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => String.
|
|
147
|
+
btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => String.fromCodePoint(`0x${p1}`)))
|
|
148
148
|
);
|
|
149
149
|
|
|
150
150
|
// src/RemoteIcon.tsx
|
|
@@ -185,7 +185,6 @@ var _RemoteIcon = class _RemoteIcon extends react_exports.PureComponent {
|
|
|
185
185
|
const icon = yield iconRegistry.getByURL(iconURL);
|
|
186
186
|
return icon.dataURI;
|
|
187
187
|
} catch (error) {
|
|
188
|
-
console.error((0, i18n_exports._)(error));
|
|
189
188
|
}
|
|
190
189
|
}
|
|
191
190
|
} else {
|
|
@@ -261,7 +260,6 @@ var _RemoteIcon = class _RemoteIcon extends react_exports.PureComponent {
|
|
|
261
260
|
const iconDataURI = `data:image/svg+xml;base64,${svgStr}`;
|
|
262
261
|
this.setState({ iconDataURI });
|
|
263
262
|
}).catch(() => {
|
|
264
|
-
console.error((0, i18n_exports._)("The icon cannot be colored properly."));
|
|
265
263
|
});
|
|
266
264
|
}
|
|
267
265
|
render() {
|
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 type IconRegistry from '@splunk/visualization-context/IconRegistry';\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\ntype IconRegistryValue = IconRegistry | null;\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 as React.Context<IconRegistryValue>;\n\n declare context: IconRegistryValue;\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 componentDidMount(): void {\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 = 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.includes('://');\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 if an icon is a relative URL path (e.g., /static/app/myapp/icon.svg)\n * @param {*} icon\n */\nexport const isRelativeUrlPath = (icon = '') => {\n if (!icon || typeof icon !== 'string') {\n return false;\n }\n // Check if it starts with / and doesn't already have a protocol\n return icon.startsWith('/') && icon.indexOf('://') === -1;\n};\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
|
-
"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,iBAA+B;AAC/B,kCAAc;AACd,IAAO,wBAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,yBAAc;AACd,IAAO,eAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,gCAAc;AACd,IAAO,sBAAS,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;;;ACWO,IAAM,mBAAmB,CAAC,EAAE,UAAU,WAAW,YAAY,YAAY,MAAM;AAClF,QAAM,eAAe,CAAC,CAAC,aAAa,aAAa,UAAU,aAAa;AACxE,QAAM,gBAAgB,CAAC,CAAC,cAAc,cAAc,UAAU,cAAc;AAC5E,QAAM,kBAAkB,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,cAAc,CAAC,CAAC;AACtE,SAAO,EAAE,gBAAgB,iBAAiB;AAC9C;AAYO,IAAM,qBAAqB,CAAC,EAAE,UAAU,WAAW,YAAY,YAAY,MAAM;AACpF,QAAM,iBAAiB,CAAC,CAAC,eAAe,eAAe,UAAU,eAAe;AAChF,QAAM,kBAAkB,CAAC,CAAC,gBAAgB,gBAAgB,UAAU,gBAAgB;AACpF,QAAM,UAAU,CAAC,CAAC,YAAY,CAAC,CAAC;AAChC,QAAM,WAAW,CAAC,cAAc,CAAC;AACjC,SAAO,EAAE,kBAAkB,mBAAmB,WAAW;AAC7D;AAOO,IAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAI5B,KAAK,mBAAmB,GAAG,EAAE,QAAQ,mBAAmB,CAAC,OAAO,OAAO,OAAO,
|
|
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 type IconRegistry from '@splunk/visualization-context/IconRegistry';\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\ntype IconRegistryValue = IconRegistry | null;\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};\n`;\n\nclass RemoteIcon extends React.PureComponent<RemoteIconProps, RemoteIconState> {\n static readonly contextType = IconContext as React.Context<IconRegistryValue>;\n\n declare context: IconRegistryValue;\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 componentDidMount(): void {\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 = this.context;\n if (iconRegistry) {\n try {\n const icon = (await iconRegistry.getByURL(iconURL)) as any;\n return icon.dataURI;\n } catch (error) /* NOSONAR - error is surfaced by rendering nothing, not logged */ {\n // fall through to null below\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 // NOSONAR - error is surfaced by leaving the icon uncolored, not logged\n });\n }\n\n render() {\n const { iconDataURI } = this.state;\n const { alt = _('Remote Icon'), width = 100, height = 100, opacity = 1, 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.includes('://');\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 if an icon is a relative URL path (e.g., /static/app/myapp/icon.svg)\n * @param {*} icon\n */\nexport const isRelativeUrlPath = (icon = '') => {\n if (!icon || typeof icon !== 'string') {\n return false;\n }\n // Check if it starts with / and doesn't already have a protocol\n return icon.startsWith('/') && !icon.includes('://');\n};\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.fromCodePoint(`0x${p1}`)));\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,sCAAc;AACd,IAAO,4BAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,kCAAc;AACd,IAAO,wBAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,yBAAc;AACd,IAAO,eAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,gCAAc;AACd,IAAO,sBAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,6BAAc;AACd,IAAO,mBAAS,aAAaA,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;AAAA,IAEb,CAAC;AAAA,EACT;AAAA,EAEA,SAAS;AACL,UAAM,EAAE,YAAY,IAAI,KAAK;AAC7B,UAAM,EAAE,UAAM,gBAAE,aAAa,GAAG,QAAQ,KAAK,SAAS,KAAK,UAAU,GAAG,YAAY,IAAI,KAAK;AAC7F,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;AAjJI,cADE,aACc,eAAc;AAI9B,cALE,aAKc,gBAAe,CAAC,QAAQ,QAAQ,UAAU,WAAW,QAAQ,YAAY,SAAS;AALtG,IAAM,aAAN;AAoJA,IAAO,qBAAQ;",
|
|
6
6
|
"names": ["defaultImport", "defaultImport", "defaultImport", "defaultImport", "defaultImport"]
|
|
7
7
|
}
|
package/RemoteImage.js
CHANGED
package/RemoteImage.js.map
CHANGED
|
@@ -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 type ImageRegistry from '@splunk/visualization-context/ImageRegistry';\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.includes('://') && 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\ntype ImageRegistryValue = ImageRegistry | null;\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 as React.Context<ImageRegistryValue>;\n\n declare context: ImageRegistryValue;\n\n constructor(props: RemoteImageProps) {\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: RemoteImageProps) {\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: string) {\n const imageRegistry = this.context;\n if (imageRegistry) {\n try {\n const image = await imageRegistry.getByURL(imageURL);\n this.setState({ imageDataURI: image.dataURI });\n } catch (error) {\n //
|
|
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;AA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A;AAGvC,IAAM,cAAN,cAAgC,4BAAkD;AAAA,EAK9E,YAAY,OAAyB;AACjC,UAAM,KAAK;AACX,SAAK,QAAQ;AAAA,MACT,cAAc;AAAA,MACd,qBAAqB,QAAQ,MAAM,mBAAmB;AAAA,IAC1D;AAAA,EACJ;AAAA,EAEA,oBAAoB;AAChB,SAAK,SAAS,KAAK,MAAM,QAAQ;AAAA,EACrC;AAAA,EAEA,mBAAmB,WAA6B;AAC5C,QAAI,UAAU,aAAa,KAAK,MAAM,UAAU;AAC5C,WAAK,SAAS,KAAK,MAAM,QAAQ;AAAA,IACrC;AACA,QAAI,UAAU,wBAAwB,KAAK,MAAM,qBAAqB;AAElE,WAAK,SAAS;AAAA,QACV,qBAAqB,KAAK,MAAM;AAAA,MACpC,CAAC;AAAA,IACL;AAAA,EACJ;AAAA,EAEM,SAAS,UAAkB;AAAA;AAC7B,YAAM,gBAAgB,KAAK;AAC3B,UAAI,eAAe;AACf,YAAI;AACA,gBAAM,QAAQ,MAAM,cAAc,SAAS,QAAQ;AACnD,eAAK,SAAS,EAAE,cAAc,MAAM,QAAQ,CAAC;AAAA,QACjD,SAAS,
|
|
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 type ImageRegistry from '@splunk/visualization-context/ImageRegistry';\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.includes('://') && 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\ntype ImageRegistryValue = ImageRegistry | null;\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 as React.Context<ImageRegistryValue>;\n\n declare context: ImageRegistryValue;\n\n constructor(props: RemoteImageProps) {\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: RemoteImageProps) {\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: string) {\n const imageRegistry = this.context;\n if (imageRegistry) {\n try {\n const image = await imageRegistry.getByURL(imageURL);\n this.setState({ imageDataURI: image.dataURI });\n } catch (error) /* NOSONAR - error is surfaced by rendering nothing, not logged */ {\n // fall through, imageDataURI stays null\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
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AACA,oBAA+B;AAC/B,0BAAc;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AAAA,EAER;AACJ;AA5DI,cADE,aACc,eAAc;AA8DlC,IAAO,sBAAQ;",
|
|
6
6
|
"names": ["defaultImport", "defaultImport", "defaultImport", "defaultImport", "defaultImport"]
|
|
7
7
|
}
|
package/SanitizeProps.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/SanitizeProps.tsx", "esm-externals:react", "esm-externals:lodash", "esm-externals:@splunk/visualization-encoding/utils/colorUtils"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-param-reassign */\nimport * as React from 'react';\nimport { isPlainObject } from 'lodash';\nimport { isColor } from './colorUtils';\n\nconst propsKeyValidators = {\n backgroundColor: isColor,\n deltaColor: isColor, // SV react-visualizations & dashboard-visualizations\n trendColor: isColor, // SV visualizations\n fontColor: isColor,\n fillColor: isColor,\n gaugeColor: isColor,\n majorColor: isColor,\n radialBackgroundColor: isColor,\n radialStrokeColor: isColor,\n sparklineFillColor: isColor,\n sparklineStrokeColor: isColor,\n strokeColor: isColor,\n strokeHighlightColor: isColor,\n headerBackgroundColor: isColor,\n rowBackgroundColorOdd: isColor,\n rowBackgroundColorEven: isColor,\n headerTextColor: isColor,\n rowTextColorOdd: isColor,\n rowTextColorEven: isColor,\n color: isColor,\n textColor: isColor,\n defaultFontColor: isColor,\n defaultBlockFontColor: isColor,\n sparklineAreaColor: isColor,\n iconColor: isColor,\n areaColor: isColor,\n nodeColor: isColor,\n nodeHighlightColor: isColor,\n linkColor: isColor,\n nodeTextColor: isColor,\n nodeValueColor: isColor,\n nodeTextHighlightColor: isColor,\n trellisBackgroundColor: isColor,\n};\n\n/**\n * Validates if a given key value pair are valid\n * based on a set of predefined rules.\n *\n * @param {string} key\n * @param {string} value\n * @returns {boolean}\n */\nfunction isValidProperty(key: string, value: string): boolean {\n const { hasOwnProperty } = Object.prototype;\n return hasOwnProperty.call(propsKeyValidators, key) ? propsKeyValidators[key](value) : true;\n}\n\n/**\n * Validates every property in the key and return\n * only valid keys\n *\n * @export\n * @template T\n * @param {T} props\n * @returns {Partial<T>}\n */\nexport function sanitize<T extends Record<string, any>>(props: T): Partial<T> {\n return Object.keys(props).reduce((accum, key) => {\n if (key === 'options' && isPlainObject(props.options)) {\n accum[key] = sanitize(props.options);\n } else if (isValidProperty(key, props[key])) {\n accum[key] = props[key];\n }\n return accum;\n }, {});\n}\n\n/**\n * Helper HOC which will sanitize invalid props\n *\n * @export\n * @param {React.ComponentType} WrappedComponent\n * @returns {React.ComponentType}\n */\nexport function withSanitizedProps<T>(\n WrappedComponent: React.ComponentType<T>\n): React.ComponentType<Partial<T>> {\n const Wrapper = (props: T) => {\n const sanitizedProps = sanitize(props);\n return <WrappedComponent {...(sanitizedProps as T)}
|
|
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,2BAAc;AACd,IAAO,iBAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,+BAAc;AACd,IAAO,qBAAS,aAAaA,iBAA8B,yBAAUA;;;AHErE,IAAM,qBAAqB;AAAA,EACvB,iBAAiB;AAAA,EACjB,YAAY;AAAA;AAAA,EACZ,YAAY;AAAA;AAAA,EACZ,WAAW;AAAA,EACX,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,uBAAuB;AAAA,EACvB,mBAAmB;AAAA,EACnB,oBAAoB;AAAA,EACpB,sBAAsB;AAAA,EACtB,aAAa;AAAA,EACb,sBAAsB;AAAA,EACtB,uBAAuB;AAAA,EACvB,uBAAuB;AAAA,EACvB,wBAAwB;AAAA,EACxB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,OAAO;AAAA,EACP,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB,uBAAuB;AAAA,EACvB,oBAAoB;AAAA,EACpB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,wBAAwB;AAAA,EACxB,wBAAwB;AAC5B;AAUA,SAAS,gBAAgB,KAAa,OAAwB;AAC1D,QAAM,EAAE,eAAe,IAAI,OAAO;AAClC,SAAO,eAAe,KAAK,oBAAoB,GAAG,IAAI,mBAAmB,GAAG,EAAE,KAAK,IAAI;AAC3F;AAWO,SAAS,SAAwC,OAAsB;AAC1E,SAAO,OAAO,KAAK,KAAK,EAAE,OAAO,CAAC,OAAO,QAAQ;AAC7C,QAAI,QAAQ,iBAAa,8BAAc,MAAM,OAAO,GAAG;AACnD,YAAM,GAAG,IAAI,SAAS,MAAM,OAAO;AAAA,IACvC,WAAW,gBAAgB,KAAK,MAAM,GAAG,CAAC,GAAG;AACzC,YAAM,GAAG,IAAI,MAAM,GAAG;AAAA,IAC1B;AACA,WAAO;AAAA,EACX,GAAG,CAAC,CAAC;AACT;AASO,SAAS,mBACZ,kBAC+B;AAC/B,QAAM,UAAU,CAAC,UAAa;AAC1B,UAAM,iBAAiB,SAAS,KAAK;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-param-reassign */\nimport * as React from 'react';\nimport { isPlainObject } from 'lodash';\nimport { isColor } from './colorUtils';\n\nconst propsKeyValidators = {\n backgroundColor: isColor,\n deltaColor: isColor, // SV react-visualizations & dashboard-visualizations\n trendColor: isColor, // SV visualizations\n fontColor: isColor,\n fillColor: isColor,\n gaugeColor: isColor,\n majorColor: isColor,\n radialBackgroundColor: isColor,\n radialStrokeColor: isColor,\n sparklineFillColor: isColor,\n sparklineStrokeColor: isColor,\n strokeColor: isColor,\n strokeHighlightColor: isColor,\n headerBackgroundColor: isColor,\n rowBackgroundColorOdd: isColor,\n rowBackgroundColorEven: isColor,\n headerTextColor: isColor,\n rowTextColorOdd: isColor,\n rowTextColorEven: isColor,\n color: isColor,\n textColor: isColor,\n defaultFontColor: isColor,\n defaultBlockFontColor: isColor,\n sparklineAreaColor: isColor,\n iconColor: isColor,\n areaColor: isColor,\n nodeColor: isColor,\n nodeHighlightColor: isColor,\n linkColor: isColor,\n nodeTextColor: isColor,\n nodeValueColor: isColor,\n nodeTextHighlightColor: isColor,\n trellisBackgroundColor: isColor,\n};\n\n/**\n * Validates if a given key value pair are valid\n * based on a set of predefined rules.\n *\n * @param {string} key\n * @param {string} value\n * @returns {boolean}\n */\nfunction isValidProperty(key: string, value: string): boolean {\n const { hasOwnProperty } = Object.prototype;\n return hasOwnProperty.call(propsKeyValidators, key) ? propsKeyValidators[key](value) : true;\n}\n\n/**\n * Validates every property in the key and return\n * only valid keys\n *\n * @export\n * @template T\n * @param {T} props\n * @returns {Partial<T>}\n */\nexport function sanitize<T extends Record<string, any>>(props: T): Partial<T> {\n return Object.keys(props).reduce((accum, key) => {\n if (key === 'options' && isPlainObject(props.options)) {\n accum[key] = sanitize(props.options);\n } else if (isValidProperty(key, props[key])) {\n accum[key] = props[key];\n }\n return accum;\n }, {});\n}\n\n/**\n * Helper HOC which will sanitize invalid props\n *\n * @export\n * @param {React.ComponentType} WrappedComponent\n * @returns {React.ComponentType}\n */\nexport function withSanitizedProps<T>(\n WrappedComponent: React.ComponentType<T>\n): React.ComponentType<Partial<T>> {\n const Wrapper = (props: T) => {\n const sanitizedProps = sanitize(props);\n // cast is required: sanitize() returns Partial<T> which is not assignable to the component's required props T\n return <WrappedComponent {...(sanitizedProps as T)} />; // NOSONAR typescript:S4325 - see note above\n };\n return Wrapper;\n}\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", "\nimport * as defaultImport from \"@splunk/visualization-encoding/utils/colorUtils\";\nexport * from \"@splunk/visualization-encoding/utils/colorUtils\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n"],
|
|
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,2BAAc;AACd,IAAO,iBAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAC,iBAA+B;AAC/B,+BAAc;AACd,IAAO,qBAAS,aAAaA,iBAA8B,yBAAUA;;;AHErE,IAAM,qBAAqB;AAAA,EACvB,iBAAiB;AAAA,EACjB,YAAY;AAAA;AAAA,EACZ,YAAY;AAAA;AAAA,EACZ,WAAW;AAAA,EACX,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,uBAAuB;AAAA,EACvB,mBAAmB;AAAA,EACnB,oBAAoB;AAAA,EACpB,sBAAsB;AAAA,EACtB,aAAa;AAAA,EACb,sBAAsB;AAAA,EACtB,uBAAuB;AAAA,EACvB,uBAAuB;AAAA,EACvB,wBAAwB;AAAA,EACxB,iBAAiB;AAAA,EACjB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,OAAO;AAAA,EACP,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB,uBAAuB;AAAA,EACvB,oBAAoB;AAAA,EACpB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,WAAW;AAAA,EACX,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,wBAAwB;AAAA,EACxB,wBAAwB;AAC5B;AAUA,SAAS,gBAAgB,KAAa,OAAwB;AAC1D,QAAM,EAAE,eAAe,IAAI,OAAO;AAClC,SAAO,eAAe,KAAK,oBAAoB,GAAG,IAAI,mBAAmB,GAAG,EAAE,KAAK,IAAI;AAC3F;AAWO,SAAS,SAAwC,OAAsB;AAC1E,SAAO,OAAO,KAAK,KAAK,EAAE,OAAO,CAAC,OAAO,QAAQ;AAC7C,QAAI,QAAQ,iBAAa,8BAAc,MAAM,OAAO,GAAG;AACnD,YAAM,GAAG,IAAI,SAAS,MAAM,OAAO;AAAA,IACvC,WAAW,gBAAgB,KAAK,MAAM,GAAG,CAAC,GAAG;AACzC,YAAM,GAAG,IAAI,MAAM,GAAG;AAAA,IAC1B;AACA,WAAO;AAAA,EACX,GAAG,CAAC,CAAC;AACT;AASO,SAAS,mBACZ,kBAC+B;AAC/B,QAAM,UAAU,CAAC,UAAa;AAC1B,UAAM,iBAAiB,SAAS,KAAK;AAErC,WAAO,4CAAC,qCAAsB,eAAsB;AAAA,EACxD;AACA,SAAO;AACX;",
|
|
6
6
|
"names": ["defaultImport", "defaultImport"]
|
|
7
7
|
}
|
package/SizeAwareWrapper.js.map
CHANGED
|
@@ -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 //
|
|
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;
|
|
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/height are intentionally retained: the jest mock in __mocks__/@splunk/visualizations-shared/SizeAwareWrapper.js reads them to simulate ResizeObserver dimensions, which jsdom cannot provide\n width?: number | string; // NOSONAR typescript:S6767 - see note above\n height?: number | string; // NOSONAR typescript:S6767 - see note above\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 = () => this.el?.parentElement;\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;AAYA,IAAM,mBAAN,cAAqC,4BAA2C;AAAA,EAAhF;AAAA;AACI;AAEA;AAiBA,sCAAa,MAAG;AAzCpB;AAyCuB,wBAAK,OAAL,mBAAS;AAAA;AAY5B,wCAAe,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,EAjCA,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,EAIA,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
|
}
|
package/VisualizationDocPage.js
CHANGED
|
@@ -150,7 +150,7 @@ var _ComponentPage = class _ComponentPage extends react_exports.Component {
|
|
|
150
150
|
}
|
|
151
151
|
render() {
|
|
152
152
|
const {
|
|
153
|
-
createComponentURL =
|
|
153
|
+
createComponentURL = () => "",
|
|
154
154
|
conceptsSection,
|
|
155
155
|
overviewSection,
|
|
156
156
|
examplesSection,
|
|
@@ -158,7 +158,6 @@ var _ComponentPage = class _ComponentPage extends react_exports.Component {
|
|
|
158
158
|
eventSection,
|
|
159
159
|
themeSection,
|
|
160
160
|
performanceSection,
|
|
161
|
-
headerOffset = 0,
|
|
162
161
|
sourceURL
|
|
163
162
|
} = this.props;
|
|
164
163
|
let basePageProps = (0, lodash_exports.pick)(this.props, "dependsOnSplunk", "description", "title");
|
|
@@ -174,32 +173,24 @@ var _ComponentPage = class _ComponentPage extends react_exports.Component {
|
|
|
174
173
|
body = examplesSection;
|
|
175
174
|
activeSection = "examples";
|
|
176
175
|
}
|
|
177
|
-
return /* @__PURE__ */ react_exports.createElement(
|
|
178
|
-
|
|
179
|
-
{
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
conceptsSection && /* @__PURE__ */ react_exports.createElement(DockingTabBar_default.Tab, { label: "Concepts", tabId: "concepts" })
|
|
192
|
-
), /* @__PURE__ */ react_exports.createElement(
|
|
193
|
-
"div",
|
|
194
|
-
{
|
|
195
|
-
style: {
|
|
196
|
-
padding: "0 30px 30px",
|
|
197
|
-
marginTop: "20px"
|
|
176
|
+
return /* @__PURE__ */ react_exports.createElement(
|
|
177
|
+
API_default,
|
|
178
|
+
__spreadValues({
|
|
179
|
+
sourceURL: sourceURL || createComponentURL(globalThis.location.pathname)
|
|
180
|
+
}, basePageProps),
|
|
181
|
+
/* @__PURE__ */ react_exports.createElement(DockingTabBar_default, { activeTabId: activeSection, onChange: this.handleSectionChange }, overviewSection && /* @__PURE__ */ react_exports.createElement(DockingTabBar_default.Tab, { label: "Overview", tabId: "overview" }), /* @__PURE__ */ react_exports.createElement(DockingTabBar_default.Tab, { label: "Examples", tabId: "examples" }), encodingSection && /* @__PURE__ */ react_exports.createElement(DockingTabBar_default.Tab, { label: "Encoding", tabId: "encoding" }), /* @__PURE__ */ react_exports.createElement(DockingTabBar_default.Tab, { label: "Options", tabId: "option" }), eventSection && /* @__PURE__ */ react_exports.createElement(DockingTabBar_default.Tab, { label: "Events", tabId: "event" }), performanceSection && /* @__PURE__ */ react_exports.createElement(DockingTabBar_default.Tab, { label: "Performance", tabId: "performance" }), themeSection && /* @__PURE__ */ react_exports.createElement(DockingTabBar_default.Tab, { label: "Themes", tabId: "theme" }), conceptsSection && /* @__PURE__ */ react_exports.createElement(DockingTabBar_default.Tab, { label: "Concepts", tabId: "concepts" })),
|
|
182
|
+
/* @__PURE__ */ react_exports.createElement(
|
|
183
|
+
"div",
|
|
184
|
+
{
|
|
185
|
+
style: {
|
|
186
|
+
padding: "0 30px 30px",
|
|
187
|
+
marginTop: "20px"
|
|
188
|
+
},
|
|
189
|
+
ref: this.handleBodyMount
|
|
198
190
|
},
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
));
|
|
191
|
+
body
|
|
192
|
+
)
|
|
193
|
+
);
|
|
203
194
|
}
|
|
204
195
|
};
|
|
205
196
|
__publicField(_ComponentPage, "currentSection", "overview");
|