{"version":3,"file":"scroll-to-new-comment-CTJex8Pi.js","sources":["../../../app/frontend/entrypoints/scroll-to-new-comment.js"],"sourcesContent":["document.addEventListener('turbo:before-stream-render', (event) => {\n const target = document.getElementById(event.detail.newStream.target);\n\n if (event.detail.newStream.action == 'prepend') scrollToNewComment(target);\n if (event.detail.newStream.action == 'append') scrollToNewComment(target, true);\n});\n\nconst scrollToNewComment = (target, subcomment = false) => {\n const scrollSettings = { block: 'start', behavior: 'smooth' };\n\n // Options for the observer (which mutations to observe)\n const config = { attributes: false, childList: true, subtree: false };\n\n // Callback function to execute when mutations are observed\n const callback = (mutationList, observer) => {\n for (const mutation of mutationList) {\n if (mutation.type === 'childList') {\n let target = subcomment ? mutation.target.lastElementChild : mutation.target;\n target.scrollIntoView(scrollSettings);\n observer.disconnect();\n }\n }\n };\n\n // Create an observer instance linked to the callback function\n const observer = new MutationObserver(callback);\n\n // Start observing the target node for configured mutations\n observer.observe(target, config);\n};\n"],"names":["event","target","scrollToNewComment","subcomment","scrollSettings","config","callback","mutationList","observer","mutation"],"mappings":"AAAA,SAAS,iBAAiB,6BAA+BA,GAAU,CACjE,MAAMC,EAAS,SAAS,eAAeD,EAAM,OAAO,UAAU,MAAM,EAEhEA,EAAM,OAAO,UAAU,QAAU,WAAWE,EAAmBD,CAAM,EACrED,EAAM,OAAO,UAAU,QAAU,UAAUE,EAAmBD,EAAQ,EAAI,CAChF,CAAC,EAED,MAAMC,EAAqB,CAACD,EAAQE,EAAa,KAAU,CACzD,MAAMC,EAAiB,CAAE,MAAO,QAAS,SAAU,QAAU,EAGvDC,EAAS,CAAE,WAAY,GAAO,UAAW,GAAM,QAAS,EAAO,EAG/DC,EAAW,CAACC,EAAcC,IAAa,CAC3C,UAAWC,KAAYF,EACjBE,EAAS,OAAS,eACPN,EAAaM,EAAS,OAAO,iBAAmBA,EAAS,QAC/D,eAAeL,CAAc,EACpCI,EAAS,WAAY,EAG1B,EAGgB,IAAI,iBAAiBF,CAAQ,EAGrC,QAAQL,EAAQI,CAAM,CACjC"}