@grafana/ui
Version:
Grafana Components Library
32 lines (29 loc) • 1.05 kB
JavaScript
import { jsx } from 'react/jsx-runtime';
import { memo, useRef, useEffect } from 'react';
import { JsonExplorer } from './json_explorer/json_explorer.mjs';
;
const JSONFormatter = memo(
({ className, json, config = { animateOpen: true }, open = 3, onDidRender }) => {
const wrapperRef = useRef(null);
useEffect(() => {
const wrapperEl = wrapperRef.current;
if (!wrapperEl) {
return;
}
const formatter = new JsonExplorer(json, open, config);
const hasChildren = wrapperEl.hasChildNodes();
if (hasChildren && wrapperEl.lastChild) {
wrapperEl.replaceChild(formatter.render(), wrapperEl.lastChild);
} else {
wrapperEl.appendChild(formatter.render());
}
if (onDidRender) {
onDidRender(formatter.json);
}
}, [json, config, open, onDidRender]);
return /* @__PURE__ */ jsx("div", { className, ref: wrapperRef });
}
);
JSONFormatter.displayName = "JSONFormatter";
export { JSONFormatter };
//# sourceMappingURL=JSONFormatter.mjs.map