@splunk/visualizations-shared 28.5.3 → 28.6.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 +8 -3
- package/Downloader.js.map +2 -2
- package/FileDownloader.js +4 -1
- package/FileDownloader.js.map +2 -2
- package/LICENSE +13 -0
- package/RemoteIcon.d.ts +1 -1
- package/RemoteIcon.js +5 -4
- package/RemoteIcon.js.map +2 -2
- package/RemoteImage.js +4 -2
- package/RemoteImage.js.map +2 -2
- package/SizeAwareWrapper.js +10 -6
- package/SizeAwareWrapper.js.map +2 -2
- package/VisualizationDocPage.js +7 -5
- package/VisualizationDocPage.js.map +1 -1
- package/iconUtils.d.ts +1 -1
- package/iconUtils.js +1 -1
- package/iconUtils.js.map +2 -2
- package/numberUtils.js +1 -1
- package/numberUtils.js.map +2 -2
- package/package.json +13 -13
- package/trellisUtils.js +6 -6
- package/trellisUtils.js.map +2 -2
- package/tsconfig.json +1 -1
- package/LICENSE.md +0 -449
package/Downloader.js
CHANGED
|
@@ -7,6 +7,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
7
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
11
|
var __export = (target, all) => {
|
|
11
12
|
for (var name in all)
|
|
12
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -29,6 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
30
|
mod
|
|
30
31
|
));
|
|
31
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
34
|
var __async = (__this, __arguments, generator) => {
|
|
33
35
|
return new Promise((resolve, reject) => {
|
|
34
36
|
var fulfilled = (value) => {
|
|
@@ -73,12 +75,14 @@ var i18n_default = "default" in defaultImport ? defaultImport.default : defaultI
|
|
|
73
75
|
var b64DecodeUnicode = (base64Data) => {
|
|
74
76
|
return decodeURIComponent(
|
|
75
77
|
atob(base64Data).split("").map((c) => {
|
|
76
|
-
|
|
78
|
+
const hex = `00${c.charCodeAt(0).toString(16)}`.slice(-2);
|
|
79
|
+
return `%${hex}`;
|
|
77
80
|
}).join("")
|
|
78
81
|
);
|
|
79
82
|
};
|
|
80
83
|
var ImageRegistryFetcher = class {
|
|
81
84
|
constructor(context) {
|
|
85
|
+
__publicField(this, "context");
|
|
82
86
|
this.context = context;
|
|
83
87
|
}
|
|
84
88
|
downloadWithProgress(url, complete, progress, error) {
|
|
@@ -89,7 +93,7 @@ var ImageRegistryFetcher = class {
|
|
|
89
93
|
}
|
|
90
94
|
return imageRegistry.getByURL(url).then((imageData) => {
|
|
91
95
|
const [mime, svgBase64] = imageData.dataURI.split("base64,");
|
|
92
|
-
if (mime
|
|
96
|
+
if (mime == null ? void 0 : mime.toLowerCase().includes("image/svg+xml")) {
|
|
93
97
|
complete(b64DecodeUnicode(svgBase64));
|
|
94
98
|
} else {
|
|
95
99
|
error((0, i18n_exports._)(`Unsupported MIME type ${mime} for url ${url}`));
|
|
@@ -159,8 +163,9 @@ var URLDownloader = class {
|
|
|
159
163
|
}
|
|
160
164
|
};
|
|
161
165
|
var Downloader = class {
|
|
166
|
+
// NOSONAR - reassigned in constructor
|
|
162
167
|
constructor(downloaders) {
|
|
163
|
-
this
|
|
168
|
+
__publicField(this, "downloaders", {});
|
|
164
169
|
this.downloaders = downloaders;
|
|
165
170
|
}
|
|
166
171
|
downloadWithProgress(url, complete, progress, error) {
|
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
|
|
5
|
-
"mappings": "
|
|
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.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", "\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;AA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Y,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,GAAG;AACR,cAAQ;AAAA,IACZ;AAEA,QAAI,OAAO;AACP,UAAI;AACA,cAAM,CAAC,OAAO,EAAE,IAAI,SAAS,MAAM,GAAG;AACtC,YAAI,KAAK,YAAY,IAAI,GAAG;AAExB,eAAK,YAAY,IAAI,EAAE,qBAAqB,KAAK,UAAU,UAAU,KAAK;AAAA,QAC9E,OAAO;AAEH,gBAAM,6BAA6B,IAAI,uBAAuB,GAAG,EAAE;AAAA,QACvE;AAAA,MACJ,SAAS,GAAG;AACR,cAAM,qCAAqC,EAAE,OAAO,EAAE;AAAA,MAC1D;AAAA,IACJ,OAAO;AAGH,eAAS,GAAG;AAAA,IAChB;AAAA,EACJ;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/FileDownloader.js
CHANGED
|
@@ -7,6 +7,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
7
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
11
|
var __export = (target, all) => {
|
|
11
12
|
for (var name in all)
|
|
12
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -29,6 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
30
|
mod
|
|
30
31
|
));
|
|
31
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
34
|
|
|
33
35
|
// src/FileDownloader.tsx
|
|
34
36
|
var FileDownloader_exports = {};
|
|
@@ -57,8 +59,9 @@ var i18n_default = "default" in defaultImport2 ? defaultImport2.default : defaul
|
|
|
57
59
|
|
|
58
60
|
// src/Downloader.ts
|
|
59
61
|
var Downloader = class {
|
|
62
|
+
// NOSONAR - reassigned in constructor
|
|
60
63
|
constructor(downloaders) {
|
|
61
|
-
this
|
|
64
|
+
__publicField(this, "downloaders", {});
|
|
62
65
|
this.downloaders = downloaders;
|
|
63
66
|
}
|
|
64
67
|
downloadWithProgress(url, complete, progress, error) {
|
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 return `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`;\n })\n .join('')\n );\n};\n\nexport class ImageRegistryFetcher implements IDownloader {\n context: ImageRegistry;\n\n constructor(context?: ImageRegistry) {\n this.context = context;\n }\n\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): Promise<void> {\n const imageRegistry = this.context;\n if (!imageRegistry) {\n error(_('Missing Image Context'));\n return Promise.resolve();\n }\n\n return imageRegistry\n .getByURL(url)\n .then(imageData => {\n const [mime, svgBase64] = imageData.dataURI.split('base64,');\n if (mime && mime.toLowerCase().indexOf('image/svg+xml') > -1) {\n complete(b64DecodeUnicode(svgBase64));\n } else {\n error(_(`Unsupported MIME type ${mime} for url ${url}`));\n }\n })\n .catch(e => {\n error(_(`Error retrieving ${url} from Image Registry, error was '${e.message}'`), e);\n });\n }\n}\n\nexport class URLDownloader implements IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // Step 1: fetch content from URL, get reader\n fetch(url)\n .then(async (response: Response): Promise<void> => {\n if (!response.ok) {\n const msg = `Fetch not Ok for ${url}, status was '${response.statusText}'`;\n // eslint-disable-next-line no-console\n console.warn(msg);\n error(msg);\n return;\n }\n const reader = response.body.getReader();\n\n // Step 2: get total length\n const contentLength = +response.headers.get('Content-Length');\n\n // Step 3: read the data\n let bytesDownloaded = 0; // length at the moment\n const chunks = []; // array of received binary chunks (comprises the body)\n let done = false;\n while (!done) {\n // eslint-disable-next-line no-await-in-loop\n const res = await reader.read();\n if (!res) {\n return;\n }\n done = res.done;\n const { value } = res;\n if (value) {\n chunks.push(value);\n bytesDownloaded += value.length;\n progress({\n // call the progress callback...can enable the UI to show progress\n bytesDownloaded,\n contentLength,\n message: `Received ${bytesDownloaded} bytes of ${\n contentLength || 'unknown size'\n }`,\n });\n }\n }\n\n // Step 4: concatenate chunks into single Uint8Array\n const chunksAll = new Uint8Array(bytesDownloaded);\n let position = 0;\n // eslint-disable-next-line no-restricted-syntax\n for (const chunk of chunks) {\n chunksAll.set(chunk, position);\n position += chunk.length;\n }\n\n progress({\n bytesDownloaded,\n contentLength,\n message: 'decoding chunks',\n });\n\n // Step 5: decode into a string\n const svg = new TextDecoder('utf-8').decode(chunksAll);\n complete(svg); // show the downloaded svg back to the caller via its completion callback\n })\n .catch((e: Error): void => {\n // Note: For CORS issue, fetch api call immediately fails without any status code or response and the error message says \"Failed to fetch\"\n // but for other issues (invalid url, not found, etc), it returns with a certain status code (406, 404, etc)\n // and empty response so further operation on the response data fails.\n const stringifiedError = e.toString();\n // eslint-disable-next-line no-console\n console.error(stringifiedError);\n // call the supplied error handling function\n if (stringifiedError.includes('Failed to fetch')) {\n error(\n `Cannot fetch the image \"${url}\" due to a cross-origin resource sharing (CORS) policy`,\n e\n );\n } else {\n error(`Fetch error for '${url}', error was '${e.toString()}'`, e);\n }\n });\n }\n}\n\nexport default class Downloader {\n private downloaders = {};\n\n constructor(downloaders: { [protocol: string]: IDownloader }) {\n this.downloaders = downloaders;\n }\n\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // url is the following:\n // data:image/svg+xml;base64....\n // http://\n // https://\n // local://\n // or otherwise return errors\n\n let protocol = '';\n let isUrl = true;\n try {\n protocol = new URL(url).protocol;\n } catch (e) {\n isUrl = false;\n }\n\n if (isUrl) {\n try {\n const [type = ''] = protocol.split(':');\n if (this.downloaders[type]) {\n // data, http(s), local....\n this.downloaders[type].downloadWithProgress(url, complete, progress, error);\n } else {\n // unknown type\n error(`Unsupported URL protocol '${type}' for SVG download: ${url}`);\n }\n } catch (e) {\n error(`Unexpected error downloading SVG: ${e.message}`);\n }\n } else {\n // the url might be literal content. <svg>...</svg>. This is kindof a hack where if you pass the downloader something\n // that is literal content, it will just return the content. Makes the code flow cleaner in layers above.\n complete(url);\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
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;;;ACuJrE,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,GAAG;AACR,cAAQ;AAAA,IACZ;AAEA,QAAI,OAAO;AACP,UAAI;AACA,cAAM,CAAC,OAAO,EAAE,IAAI,SAAS,MAAM,GAAG;AACtC,YAAI,KAAK,YAAY,IAAI,GAAG;AAExB,eAAK,YAAY,IAAI,EAAE,qBAAqB,KAAK,UAAU,UAAU,KAAK;AAAA,QAC9E,OAAO;AAEH,gBAAM,6BAA6B,IAAI,uBAAuB,GAAG,EAAE;AAAA,QACvE;AAAA,MACJ,SAAS,GAAG;AACR,cAAM,qCAAqC,EAAE,OAAO,EAAE;AAAA,MAC1D;AAAA,IACJ,OAAO;AAGH,eAAS,GAAG;AAAA,IAChB;AAAA,EACJ;AACJ;;;AHzKO,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/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2026 Splunk Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/RemoteIcon.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ declare class RemoteIcon extends React.PureComponent<RemoteIconProps, RemoteIcon
|
|
|
18
18
|
context: IconRegistryValue;
|
|
19
19
|
static readonly BASIC_SHAPES: string[];
|
|
20
20
|
constructor(props: RemoteIconProps);
|
|
21
|
-
|
|
21
|
+
componentDidMount(): void;
|
|
22
22
|
componentDidUpdate(prevProps: any): void;
|
|
23
23
|
/**
|
|
24
24
|
* Check if the iconURL is a registry URL/dataURI/direct URL and fetch from the registry when required
|
package/RemoteIcon.js
CHANGED
|
@@ -7,6 +7,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
7
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
11
|
var __export = (target, all) => {
|
|
11
12
|
for (var name in all)
|
|
12
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -29,6 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
30
|
mod
|
|
30
31
|
));
|
|
31
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
34
|
var __async = (__this, __arguments, generator) => {
|
|
33
35
|
return new Promise((resolve, reject) => {
|
|
34
36
|
var fulfilled = (value) => {
|
|
@@ -160,8 +162,7 @@ var _RemoteIcon = class _RemoteIcon extends react_exports.PureComponent {
|
|
|
160
162
|
super(props);
|
|
161
163
|
this.state = { iconDataURI: null };
|
|
162
164
|
}
|
|
163
|
-
|
|
164
|
-
UNSAFE_componentWillMount() {
|
|
165
|
+
componentDidMount() {
|
|
165
166
|
this.getIcon(this.props.iconURL, this.props.color);
|
|
166
167
|
}
|
|
167
168
|
componentDidUpdate(prevProps) {
|
|
@@ -282,8 +283,8 @@ var _RemoteIcon = class _RemoteIcon extends react_exports.PureComponent {
|
|
|
282
283
|
));
|
|
283
284
|
}
|
|
284
285
|
};
|
|
285
|
-
_RemoteIcon
|
|
286
|
-
_RemoteIcon
|
|
286
|
+
__publicField(_RemoteIcon, "contextType", IconContext_default);
|
|
287
|
+
__publicField(_RemoteIcon, "BASIC_SHAPES", ["path", "rect", "circle", "ellipse", "line", "polyline", "polygon"]);
|
|
287
288
|
var RemoteIcon = _RemoteIcon;
|
|
288
289
|
var RemoteIcon_default = RemoteIcon;
|
|
289
290
|
//# sourceMappingURL=RemoteIcon.js.map
|
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 // eslint-disable-next-line camelcase\n UNSAFE_componentWillMount() {\n this.getIcon(this.props.iconURL, this.props.color);\n }\n\n componentDidUpdate(prevProps) {\n if (prevProps.iconURL !== this.props.iconURL || prevProps.color !== this.props.color) {\n this.getIcon(this.props.iconURL, this.props.color);\n }\n }\n\n /**\n * Check if the iconURL is a registry URL/dataURI/direct URL and fetch from the registry when required\n * @param {String} iconURL\n * @param {String} color\n */\n async getIcon(iconURL, color) {\n const getIconDataURI = async () => {\n if (this.isRegistryURL(iconURL)) {\n const iconRegistry = this.context;\n if (iconRegistry) {\n try {\n const icon = (await iconRegistry.getByURL(iconURL)) as any;\n return icon.dataURI;\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(_(error));\n }\n }\n } else {\n return iconURL;\n }\n return null;\n };\n\n const iconDataURI = await getIconDataURI();\n\n if (color) {\n this.colorIcon(iconDataURI, color);\n } else {\n this.setState({ iconDataURI });\n }\n }\n\n /**\n * check if icon is a registry url\n * @param {String} src\n */\n isRegistryURL(src = '') {\n const [type] = src.split('://');\n return type !== 'http' && type !== 'https' && !src.startsWith('data:image/svg+xml;base64');\n }\n\n /*\n * Color the icon:\n * parse svg elements from the dataURI, change color style of svg, and change fill/stroke attribute/style of each svg basic shapes\n * in the svg element to currentColor. At the end, convert the modified svg back to dataURI string.\n *\n * Limitation:\n * if the svg is created with multiple pathes with different fill attributes, this method would\n * convert all pathes' fill attribute to the color prop. It may change the view of the svg icon.\n *\n * @method colorIcon\n * @params {DataURI} dataURI\n * @params {String} color e.g. 'red' || '#ffffff'\n */\n colorIcon(dataURI, color) {\n fetch(dataURI)\n .then(response => response.text())\n .then(text => {\n const parser = new DOMParser();\n const xmlDoc = parser.parseFromString(text, 'text/xml');\n const svg = xmlDoc.getElementsByTagName('svg')[0];\n const children = svg.querySelectorAll('*');\n svg.style.color = color;\n // eslint-disable-next-line no-restricted-syntax\n for (const child of children) {\n if (RemoteIcon.BASIC_SHAPES.includes(child.tagName)) {\n const fillAttr = child.getAttribute('fill');\n const fillStyle = (child as SVGElement).style?.fill;\n const strokeAttr = child.getAttribute('stroke');\n const strokeStyle = (child as SVGElement).style?.stroke;\n if (\n shouldChangeFill({\n fillAttr,\n fillStyle,\n strokeAttr,\n strokeStyle,\n })\n ) {\n (child as SVGElement).style.fill = '';\n child.setAttribute('fill', 'currentColor');\n }\n\n if (\n shouldChangeStroke({\n fillAttr,\n fillStyle,\n strokeAttr,\n strokeStyle,\n })\n ) {\n (child as SVGElement).style.stroke = '';\n child.setAttribute('stroke', 'currentColor');\n }\n }\n }\n const s = xmlserializer.serializeToString(svg);\n const svgStr = b64EncodeUnicode(s);\n const iconDataURI = `data:image/svg+xml;base64,${svgStr}`;\n this.setState({ iconDataURI });\n })\n .catch(() => {\n // eslint-disable-next-line no-console\n console.error(_('The icon cannot be colored properly.'));\n });\n }\n\n render() {\n const { iconDataURI } = this.state;\n const { alt = _('Remote Icon'), width = 100, height = 100, opacity = 1.0, onIconClick } = this.props;\n if (!iconDataURI) {\n return null;\n }\n return (\n <IconContainer width={width} height={height} onClick={onIconClick}>\n <ColoredIcon\n src={iconDataURI}\n alt={alt}\n width={width}\n height={height}\n opacity={opacity}\n referrerPolicy=\"no-referrer\"\n />\n </IconContainer>\n );\n }\n}\n\nexport default RemoteIcon;\n", "\nimport * as defaultImport from \"react\";\nexport * from \"react\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"styled-components\";\nexport * from \"styled-components\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"xmlserializer\";\nexport * from \"xmlserializer\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"@splunk/ui-utils/i18n\";\nexport * from \"@splunk/ui-utils/i18n\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"@splunk/visualization-context/IconContext\";\nexport * from \"@splunk/visualization-context/IconContext\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"lodash/isNumber\";\nexport * from \"lodash/isNumber\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "import isNumber from 'lodash/isNumber';\n\n/**\n * convert number to px\n * @param {*} number\n */\nexport const toPx = (number, defaultNumber = 0) =>\n isNumber(number) ? `${number}px` : number || toPx(defaultNumber);\n\n/**\n * generate width/height css properties\n * @param {*} param0\n */\nexport const toDimension = ({ width, height }) => {\n let css = '';\n if (width) {\n css = `width: ${toPx(width)};`;\n }\n if (height) {\n // only add a linebreak if width was also set\n css = `${css}${width ? '\\n' : ''}height: ${toPx(height)};`;\n }\n return css;\n};\n\n/**\n * generate margin css property\n */\nexport const arrayToCSSProp = (prop, vals = [0, 0, 0, 0]) => {\n if (Array.isArray(vals)) {\n return `\n ${prop}: ${toPx(vals[0])} ${toPx(vals[1])} ${toPx(vals[2])} ${toPx(vals[3])};\n `;\n }\n\n return `${prop}: ${toPx(vals)};`;\n};\n\n/**\n * generate margin css property\n */\nexport const toMargin = (margins = [0, 0, 0, 0]) => arrayToCSSProp('margin', margins);\n\n/**\n * generate padding css property\n */\nexport const toPadding = (paddings = [0, 0, 0, 0]) => arrayToCSSProp('padding', paddings);\n", "/**\n * check if an icon is considered as remote icon\n * @param {*} icon\n */\nexport const isRemoteIcon = (icon = '') => icon.indexOf('://') > -1;\n\n/**\n * check if an icon is a dataURI\n * @param {*} icon\n */\nexport const isDataURI = (icon = '') => icon.startsWith('data:image/svg+xml;base64');\n\n/**\n * check 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": "
|
|
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;A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AAN;AAsJA,IAAO,qBAAQ;",
|
|
6
6
|
"names": ["defaultImport", "defaultImport", "defaultImport", "defaultImport", "defaultImport"]
|
|
7
7
|
}
|
package/RemoteImage.js
CHANGED
|
@@ -7,6 +7,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
7
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
11
|
var __export = (target, all) => {
|
|
11
12
|
for (var name in all)
|
|
12
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -29,6 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
30
|
mod
|
|
30
31
|
));
|
|
31
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
34
|
var __async = (__this, __arguments, generator) => {
|
|
33
35
|
return new Promise((resolve, reject) => {
|
|
34
36
|
var fulfilled = (value) => {
|
|
@@ -128,7 +130,7 @@ var toDimension = ({ width, height }) => {
|
|
|
128
130
|
// src/RemoteImage.tsx
|
|
129
131
|
var isRemoteImage = (src = "") => {
|
|
130
132
|
const [type] = src.split("://");
|
|
131
|
-
return src.
|
|
133
|
+
return src.includes("://") && type !== "http" && type !== "https";
|
|
132
134
|
};
|
|
133
135
|
var toImageDimensions = (props) => {
|
|
134
136
|
if (props.shouldPreserveAspectRatio) {
|
|
@@ -200,6 +202,6 @@ var RemoteImage = class extends react_exports.PureComponent {
|
|
|
200
202
|
);
|
|
201
203
|
}
|
|
202
204
|
};
|
|
203
|
-
RemoteImage
|
|
205
|
+
__publicField(RemoteImage, "contextType", ImageContext_default);
|
|
204
206
|
var RemoteImage_default = RemoteImage;
|
|
205
207
|
//# sourceMappingURL=RemoteImage.js.map
|
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.
|
|
5
|
-
"mappings": "
|
|
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 // eslint-disable-next-line no-console\n console.error(error);\n }\n }\n }\n\n render() {\n const { imageDataURI } = this.state;\n const { width, height, title } = this.props;\n\n if (!imageDataURI) {\n return null;\n }\n return (\n <Image\n src={imageDataURI}\n shouldPreserveAspectRatio={this.state.preserveAspectRatio}\n width={width}\n height={height}\n alt={_(title)}\n onError={e => {\n (e.target as HTMLImageElement).alt = _('Image not found');\n }}\n />\n );\n }\n}\n\nexport default RemoteImage;\n", "\nimport * as defaultImport from \"react\";\nexport * from \"react\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"styled-components\";\nexport * from \"styled-components\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"lodash\";\nexport * from \"lodash\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"@splunk/ui-utils/i18n\";\nexport * from \"@splunk/ui-utils/i18n\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"@splunk/visualization-context/ImageContext\";\nexport * from \"@splunk/visualization-context/ImageContext\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"lodash/isNumber\";\nexport * from \"lodash/isNumber\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "import isNumber from 'lodash/isNumber';\n\n/**\n * convert number to px\n * @param {*} number\n */\nexport const toPx = (number, defaultNumber = 0) =>\n isNumber(number) ? `${number}px` : number || toPx(defaultNumber);\n\n/**\n * generate width/height css properties\n * @param {*} param0\n */\nexport const toDimension = ({ width, height }) => {\n let css = '';\n if (width) {\n css = `width: ${toPx(width)};`;\n }\n if (height) {\n // only add a linebreak if width was also set\n css = `${css}${width ? '\\n' : ''}height: ${toPx(height)};`;\n }\n return css;\n};\n\n/**\n * generate margin css property\n */\nexport const arrayToCSSProp = (prop, vals = [0, 0, 0, 0]) => {\n if (Array.isArray(vals)) {\n return `\n ${prop}: ${toPx(vals[0])} ${toPx(vals[1])} ${toPx(vals[2])} ${toPx(vals[3])};\n `;\n }\n\n return `${prop}: ${toPx(vals)};`;\n};\n\n/**\n * generate margin css property\n */\nexport const toMargin = (margins = [0, 0, 0, 0]) => arrayToCSSProp('margin', margins);\n\n/**\n * generate padding css property\n */\nexport const toPadding = (paddings = [0, 0, 0, 0]) => arrayToCSSProp('padding', paddings);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AACA,oBAA+B;AAC/B,0BAAc;AACd,IAAO,gBAAS,aAAa,gBAA8B,wBAAU;;;ACHrE;AAAA;AAAA;AAAA;AACA,IAAAA,iBAA+B;AAC/B,sCAAc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
"names": ["defaultImport", "defaultImport", "defaultImport", "defaultImport", "defaultImport"]
|
|
7
7
|
}
|
package/SizeAwareWrapper.js
CHANGED
|
@@ -7,6 +7,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
7
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
11
|
var __export = (target, all) => {
|
|
11
12
|
for (var name in all)
|
|
12
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -29,6 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
30
|
mod
|
|
30
31
|
));
|
|
31
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
34
|
|
|
33
35
|
// src/SizeAwareWrapper.tsx
|
|
34
36
|
var SizeAwareWrapper_exports = {};
|
|
@@ -66,17 +68,19 @@ var styles = {
|
|
|
66
68
|
var SizeAwareWrapper = class extends react_exports.PureComponent {
|
|
67
69
|
constructor() {
|
|
68
70
|
super(...arguments);
|
|
69
|
-
this
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
__publicField(this, "ro");
|
|
72
|
+
__publicField(this, "el");
|
|
73
|
+
__publicField(this, "getElement", () => {
|
|
74
|
+
var _a;
|
|
75
|
+
return (_a = this.el) == null ? void 0 : _a.parentElement;
|
|
76
|
+
});
|
|
77
|
+
__publicField(this, "handleResize", (entries) => {
|
|
74
78
|
const { onResize = lodash_exports.noop } = this.props;
|
|
75
79
|
entries.forEach((entry) => {
|
|
76
80
|
const { width, height } = entry.contentRect;
|
|
77
81
|
onResize(width, height);
|
|
78
82
|
});
|
|
79
|
-
};
|
|
83
|
+
});
|
|
80
84
|
}
|
|
81
85
|
componentDidMount() {
|
|
82
86
|
const resizableElement = this.getElement();
|
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 // eslint-disable-next-line\n width?: number | string;\n // eslint-disable-next-line\n height?: number | string;\n}\n\nclass SizeAwareWrapper extends React.PureComponent<SizeAwareWrapperProps, null> {\n ro: ResizeObserver | { observe(): void; unobserve(): void };\n\n el: HTMLDivElement;\n\n componentDidMount() {\n const resizableElement = this.getElement();\n if (resizableElement) {\n this.ro = this.getResizeObserver();\n this.ro.observe(resizableElement);\n }\n }\n\n componentWillUnmount() {\n const resizableElement = this.getElement();\n if (resizableElement && this.ro) {\n this.ro.unobserve(resizableElement);\n }\n }\n\n getElement = () =>
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nimport { noop } from 'lodash';\n\nconst styles: React.CSSProperties = {\n position: 'absolute',\n width: 0,\n height: 0,\n visibility: 'hidden',\n display: 'none',\n};\n\ninterface SizeAwareWrapperProps {\n onResize: (width: number, height: number) => void;\n // This was to use width and height as props and then check to see if the values have changed inside the handleResize function\n // Some components need a double render to 'settle' and are using this so no check is needed.\n // However until that is fixed unit tests rely on these props so keeping as optional.\n // eslint-disable-next-line\n width?: number | string;\n // eslint-disable-next-line\n height?: number | string;\n}\n\nclass SizeAwareWrapper extends React.PureComponent<SizeAwareWrapperProps, null> {\n ro: ResizeObserver | { observe(): void; unobserve(): void };\n\n el: HTMLDivElement;\n\n componentDidMount() {\n const resizableElement = this.getElement();\n if (resizableElement) {\n this.ro = this.getResizeObserver();\n this.ro.observe(resizableElement);\n }\n }\n\n componentWillUnmount() {\n const resizableElement = this.getElement();\n if (resizableElement && this.ro) {\n this.ro.unobserve(resizableElement);\n }\n }\n\n getElement = () => 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;AAaA,IAAM,mBAAN,cAAqC,4BAA2C;AAAA,EAAhF;AAAA;AACI;AAEA;AAiBA,sCAAa,MAAG;AA1CpB;AA0CuB,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
|
@@ -46,6 +46,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
46
46
|
mod
|
|
47
47
|
));
|
|
48
48
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
49
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
49
50
|
|
|
50
51
|
// src/VisualizationDocPage.tsx
|
|
51
52
|
var VisualizationDocPage_exports = {};
|
|
@@ -98,10 +99,11 @@ var previewVizMessage_default = previewVizMessage;
|
|
|
98
99
|
var _ComponentPage = class _ComponentPage extends react_exports.Component {
|
|
99
100
|
constructor(args) {
|
|
100
101
|
super(args);
|
|
101
|
-
this
|
|
102
|
+
__publicField(this, "bodyEl");
|
|
103
|
+
__publicField(this, "handleBodyMount", (el) => {
|
|
102
104
|
this.bodyEl = el;
|
|
103
|
-
};
|
|
104
|
-
this
|
|
105
|
+
});
|
|
106
|
+
__publicField(this, "handleSectionChange", (e, { selectedTabId }) => {
|
|
105
107
|
_ComponentPage.currentSection = selectedTabId;
|
|
106
108
|
this.setState({ activeSection: selectedTabId }, () => {
|
|
107
109
|
const { top } = this.bodyEl.getBoundingClientRect();
|
|
@@ -110,7 +112,7 @@ var _ComponentPage = class _ComponentPage extends react_exports.Component {
|
|
|
110
112
|
window.scroll(0, target);
|
|
111
113
|
}
|
|
112
114
|
});
|
|
113
|
-
};
|
|
115
|
+
});
|
|
114
116
|
this.state = { activeSection: _ComponentPage.currentSection };
|
|
115
117
|
}
|
|
116
118
|
renderBody() {
|
|
@@ -200,7 +202,7 @@ var _ComponentPage = class _ComponentPage extends react_exports.Component {
|
|
|
200
202
|
));
|
|
201
203
|
}
|
|
202
204
|
};
|
|
203
|
-
_ComponentPage
|
|
205
|
+
__publicField(_ComponentPage, "currentSection", "overview");
|
|
204
206
|
var ComponentPage = _ComponentPage;
|
|
205
207
|
var VisualizationDocPage_default = ComponentPage;
|
|
206
208
|
//# sourceMappingURL=VisualizationDocPage.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/VisualizationDocPage.tsx", "esm-externals:react", "esm-externals:lodash", "esm-externals:@splunk/react-docs/DockingTabBar", "esm-externals:@splunk/react-docs/API", "src/previewVizMessage.ts"],
|
|
4
4
|
"sourcesContent": ["import * as React from 'react';\nimport { noop, pick } from 'lodash';\nimport DockingTabBar from '@splunk/react-docs/DockingTabBar';\nimport APIPage from '@splunk/react-docs/API';\nimport previewVizMessage from './previewVizMessage';\n\ninterface ComponentPageProps {\n createComponentURL: (componentName: string) => string;\n dependsOnSplunk: boolean;\n status: string;\n description: string;\n overviewSection: React.ReactNode;\n conceptsSection: React.ReactNode;\n examplesSection: React.ReactNode;\n optionSection: React.ReactNode;\n encodingSection: React.ReactNode;\n eventSection: React.ReactNode;\n themeSection: React.ReactNode;\n performanceSection: React.ReactNode;\n headerOffset: number;\n sourceURL: string;\n title: string;\n}\n\ninterface ComponentPageState {\n activeSection: string;\n}\n\nclass ComponentPage extends React.Component<ComponentPageProps, ComponentPageState> {\n private static currentSection = 'overview';\n\n bodyEl: any;\n\n constructor(args) {\n super(args);\n this.state = { activeSection: ComponentPage.currentSection };\n }\n\n handleBodyMount = el => {\n this.bodyEl = el;\n };\n\n handleSectionChange = (e, { selectedTabId }) => {\n ComponentPage.currentSection = selectedTabId;\n this.setState({ activeSection: selectedTabId }, () => {\n // After the new section loads, scroll to the top of the section.\n const { top } = this.bodyEl.getBoundingClientRect();\n if (top < window.scrollY) {\n const target = top + window.scrollY - 90;\n window.scroll(0, target);\n }\n });\n };\n\n renderBody() {\n const {\n encodingSection,\n optionSection,\n overviewSection,\n conceptsSection,\n examplesSection,\n eventSection,\n themeSection,\n performanceSection,\n } = this.props;\n const { activeSection } = this.state;\n switch (activeSection) {\n case 'concepts':\n return conceptsSection;\n case 'overview':\n return overviewSection;\n case 'examples':\n return examplesSection;\n case 'encoding':\n return encodingSection;\n case 'option':\n return optionSection;\n case 'event':\n return eventSection;\n case 'theme':\n return themeSection;\n case 'performance':\n return performanceSection;\n default:\n return null;\n }\n }\n\n render() {\n const {\n createComponentURL = noop,\n conceptsSection,\n overviewSection,\n examplesSection,\n encodingSection,\n eventSection,\n themeSection,\n performanceSection,\n headerOffset = 0,\n sourceURL,\n } = this.props;\n let basePageProps = pick(this.props, 'dependsOnSplunk', 'description', 'title');\n\n if (this.props.status === 'preview') {\n basePageProps = {\n ...basePageProps,\n description: `#### ${previewVizMessage} \\n ${basePageProps.description || ''}`,\n };\n }\n\n let { activeSection } = this.state;\n let body = this.renderBody();\n\n if (!body) {\n body = examplesSection;\n activeSection = 'examples';\n }\n return (\n <APIPage sourceURL={sourceURL || createComponentURL(window.location.pathname)} {...basePageProps}>\n <DockingTabBar\n activeTabId={activeSection}\n offset={headerOffset}\n onChange={this.handleSectionChange}\n >\n {overviewSection && <DockingTabBar.Tab label=\"Overview\" tabId=\"overview\" />}\n <DockingTabBar.Tab label=\"Examples\" tabId=\"examples\" />\n {encodingSection && <DockingTabBar.Tab label=\"Encoding\" tabId=\"encoding\" />}\n <DockingTabBar.Tab label=\"Options\" tabId=\"option\" />\n {eventSection && <DockingTabBar.Tab label=\"Events\" tabId=\"event\" />}\n {performanceSection && <DockingTabBar.Tab label=\"Performance\" tabId=\"performance\" />}\n {themeSection && <DockingTabBar.Tab label=\"Themes\" tabId=\"theme\" />}\n {conceptsSection && <DockingTabBar.Tab label=\"Concepts\" tabId=\"concepts\" />}\n </DockingTabBar>\n <div\n style={{\n padding: '0 30px 30px',\n marginTop: '20px',\n }}\n ref={this.handleBodyMount}\n >\n {body}\n </div>\n </APIPage>\n );\n }\n}\n\nexport default ComponentPage;\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/react-docs/DockingTabBar\";\nexport * from \"@splunk/react-docs/DockingTabBar\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "\nimport * as defaultImport from \"@splunk/react-docs/API\";\nexport * from \"@splunk/react-docs/API\";\nexport default ('default' in defaultImport ? defaultImport.default : defaultImport);\n", "const previewVizMessage =\n '\u26A0\uFE0F This is a preview of a new visualization component. Minor updates and bug fixes should be expected.';\n\nexport default previewVizMessage;\n"],
|
|
5
|
-
"mappings": "
|
|
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;;;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,wBAAc;AACd,IAAO,cAAS,aAAaA,iBAA8B,yBAAUA;;;ACHrE,IAAM,oBACF;AAEJ,IAAO,4BAAQ;;;ALyBf,IAAM,iBAAN,MAAM,uBAA4B,wBAAkD;AAAA,EAKhF,YAAY,MAAM;AACd,UAAM,IAAI;AAHd;AAOA,2CAAkB,QAAM;AACpB,WAAK,SAAS;AAAA,IAClB;AAEA,+CAAsB,CAAC,GAAG,EAAE,cAAc,MAAM;AAC5C,qBAAc,iBAAiB;AAC/B,WAAK,SAAS,EAAE,eAAe,cAAc,GAAG,MAAM;AAElD,cAAM,EAAE,IAAI,IAAI,KAAK,OAAO,sBAAsB;AAClD,YAAI,MAAM,OAAO,SAAS;AACtB,gBAAM,SAAS,MAAM,OAAO,UAAU;AACtC,iBAAO,OAAO,GAAG,MAAM;AAAA,QAC3B;AAAA,MACJ,CAAC;AAAA,IACL;AAjBI,SAAK,QAAQ,EAAE,eAAe,eAAc,eAAe;AAAA,EAC/D;A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sBAAc,KAAd,EAAkB,OAAM,YAAW,OAAM,YAAW;AAAA,MACpD,mBAAmB,4CAAC,sBAAc,KAAd,EAAkB,OAAM,YAAW,OAAM,YAAW;AAAA,MACzE,4CAAC,sBAAc,KAAd,EAAkB,OAAM,WAAU,OAAM,UAAS;AAAA,MACjD,gBAAgB,4CAAC,sBAAc,KAAd,EAAkB,OAAM,UAAS,OAAM,SAAQ;AAAA,MAChE,sBAAsB,4CAAC,sBAAc,KAAd,EAAkB,OAAM,eAAc,OAAM,eAAc;AAAA,MACjF,gBAAgB,4CAAC,sBAAc,KAAd,EAAkB,OAAM,UAAS,OAAM,SAAQ;AAAA,MAChE,mBAAmB,4CAAC,sBAAc,KAAd,EAAkB,OAAM,YAAW,OAAM,YAAW;AAAA,IAC7E,GACA;AAAA,MAAC;AAAA;AAAA,QACG,OAAO;AAAA,UACH,SAAS;AAAA,UACT,WAAW;AAAA,QACf;AAAA,QACA,KAAK,KAAK;AAAA;AAAA,MAET;AAAA,IACL,CACJ;AAAA,EAER;AACJ;AApHI,cADE,gBACa,kBAAiB;AADpC,IAAM,gBAAN;AAuHA,IAAO,+BAAQ;",
|
|
6
6
|
"names": ["defaultImport", "defaultImport", "defaultImport"]
|
|
7
7
|
}
|
package/iconUtils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function isRemoteIcon(icon?: any):
|
|
1
|
+
export function isRemoteIcon(icon?: any): any;
|
|
2
2
|
export function isDataURI(icon?: any): any;
|
|
3
3
|
export function isRelativeUrlPath(icon?: any): boolean;
|
|
4
4
|
export function shouldChangeFill({ fillAttr, fillStyle, strokeAttr, strokeStyle }: {
|