@grafana/ui
Version:
Grafana Components Library
36 lines (31 loc) • 1.17 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var json_explorer = require('./json_explorer/json_explorer.cjs');
;
const JSONFormatter = React.memo(
({ className, json, config = { animateOpen: true }, open = 3, onDidRender }) => {
const wrapperRef = React.useRef(null);
React.useEffect(() => {
const wrapperEl = wrapperRef.current;
if (!wrapperEl) {
return;
}
const formatter = new json_explorer.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__ */ jsxRuntime.jsx("div", { className, ref: wrapperRef });
}
);
JSONFormatter.displayName = "JSONFormatter";
exports.JSONFormatter = JSONFormatter;
//# sourceMappingURL=JSONFormatter.cjs.map