{"version":3,"file":"JSONFormatter.mjs","sources":["../../../../src/components/JSONFormatter/JSONFormatter.tsx"],"sourcesContent":["import { memo, useRef, useEffect } from 'react';\n\nimport { JsonExplorer, JsonExplorerConfig } from './json_explorer/json_explorer'; // We have made some monkey-patching of json-formatter-js so we can't switch right now\n\ninterface Props {\n  className?: string;\n  json: {};\n  config?: JsonExplorerConfig;\n  open?: number;\n  onDidRender?: (formattedJson: {}) => void;\n}\n\nexport const JSONFormatter = memo<Props>(\n  ({ className, json, config = { animateOpen: true }, open = 3, onDidRender }) => {\n    const wrapperRef = useRef<HTMLDivElement>(null);\n\n    useEffect(() => {\n      const wrapperEl = wrapperRef.current;\n      if (!wrapperEl) {\n        return;\n      }\n\n      const formatter = new JsonExplorer(json, open, config);\n      const hasChildren = wrapperEl.hasChildNodes();\n\n      if (hasChildren && wrapperEl.lastChild) {\n        wrapperEl.replaceChild(formatter.render(), wrapperEl.lastChild);\n      } else {\n        wrapperEl.appendChild(formatter.render());\n      }\n\n      if (onDidRender) {\n        onDidRender(formatter.json);\n      }\n    }, [json, config, open, onDidRender]);\n\n    return <div className={className} ref={wrapperRef} />;\n  }\n);\n\nJSONFormatter.displayName = 'JSONFormatter';\n"],"names":[],"mappings":";;;;;AAYO,MAAM,aAAA,GAAgB,IAAA;AAAA,EAC3B,CAAC,EAAE,SAAA,EAAW,IAAA,EAAM,MAAA,GAAS,EAAE,WAAA,EAAa,IAAA,EAAK,EAAG,IAAA,GAAO,CAAA,EAAG,WAAA,EAAY,KAAM;AAC9E,IAAA,MAAM,UAAA,GAAa,OAAuB,IAAI,CAAA;AAE9C,IAAA,SAAA,CAAU,MAAM;AACd,MAAA,MAAM,YAAY,UAAA,CAAW,OAAA;AAC7B,MAAA,IAAI,CAAC,SAAA,EAAW;AACd,QAAA;AAAA,MACF;AAEA,MAAA,MAAM,SAAA,GAAY,IAAI,YAAA,CAAa,IAAA,EAAM,MAAM,MAAM,CAAA;AACrD,MAAA,MAAM,WAAA,GAAc,UAAU,aAAA,EAAc;AAE5C,MAAA,IAAI,WAAA,IAAe,UAAU,SAAA,EAAW;AACtC,QAAA,SAAA,CAAU,YAAA,CAAa,SAAA,CAAU,MAAA,EAAO,EAAG,UAAU,SAAS,CAAA;AAAA,MAChE,CAAA,MAAO;AACL,QAAA,SAAA,CAAU,WAAA,CAAY,SAAA,CAAU,MAAA,EAAQ,CAAA;AAAA,MAC1C;AAEA,MAAA,IAAI,WAAA,EAAa;AACf,QAAA,WAAA,CAAY,UAAU,IAAI,CAAA;AAAA,MAC5B;AAAA,IACF,GAAG,CAAC,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,WAAW,CAAC,CAAA;AAEpC,IAAA,uBAAO,GAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAsB,GAAA,EAAK,UAAA,EAAY,CAAA;AAAA,EACrD;AACF;AAEA,aAAA,CAAc,WAAA,GAAc,eAAA;;;;"}