@jaspersoft/jv-tools
Version:
Tools for working with JasperReports Server's Visualize.js
61 lines (60 loc) • 1.79 kB
JavaScript
import { useState as V, useRef as b, useEffect as j } from "react";
const m = (e, t) => {
e != null && e.errorCallback ? e == null || e.errorCallback(t) : console.error(String(t));
}, S = (e, t) => {
const [r, n] = V(
null
), o = b();
return j(() => {
if (JSON.stringify(o.current) === JSON.stringify(e))
return;
o.current = e, T(e.visualizePath)().then((s) => {
let u = {
server: e.server,
auth: e.auth || {}
};
e.publicPath && (u = { ...u, publicPath: e.publicPath }), s(
u,
(a) => {
const h = a.server !== void 0 ? a : {
...a,
server: e.server
};
n({ v: h });
},
(a) => m(t, a)
);
}).catch(
(s) => m(t, s)
);
}, [e]), r;
};
let i;
const c = {}, z = 60 * 1e3, P = "", v = (e, t = z) => new Promise((r, n) => {
const o = setTimeout(() => {
n(
`Failed to load visualizejs. Either error or timeout occurred. url: [${e}]`
);
}, t), l = document.createElement("script");
l.addEventListener("load", function() {
clearTimeout(o), r();
});
const s = document.head || document.getElementsByTagName("head")[0];
l.src = e, s.insertBefore(l, s.firstChild);
}), d = () => {
const e = window.visualize;
return e && e.noConflict();
}, p = () => Promise.reject(
"No visualizejs found in the global scope. Please add script tag to your page or use url parameter to load visualizejs"
), E = () => (i || (i = d()), i ? Promise.resolve(i) : p()), T = (e, t) => !e && d() ? E : (e || (e = P), async () => {
if (c[e])
return c[e];
await v(e, t);
const r = d();
return r ? (c[e] = r, r) : p();
});
export {
S as useVisualize,
T as visualizejsLoader
};
//# sourceMappingURL=index.es.js.map