{"version":3,"file":"table_to_csv-B9klH4Dx.js","sources":["../../../app/assets/javascripts/page_includes/table_to_csv.js"],"sourcesContent":["export const exportTableToCSV = (tableIdentifier, filename = 'export.csv') => {\n const table = document.querySelector(tableIdentifier)\n\n if (table) {\n const stringifiedCSVData = tableToCSVData(table)\n const csvFile = new Blob([stringifiedCSVData], { type: 'text/csv' })\n\n let downloadLink = document.createElement('a')\n downloadLink.download = filename\n downloadLink.href = window.URL.createObjectURL(csvFile)\n downloadLink.style.display = 'none'\n document.body.appendChild(downloadLink)\n\n downloadLink.click()\n\n document.body.removeChild(downloadLink)\n }\n}\n\nconst tableToCSVData = (table) => {\n let csvData = []\n const rows = table.querySelectorAll('tr')\n\n rows.forEach((row) => {\n let rowData = []\n const cols = row.querySelectorAll('td, th')\n\n cols.forEach((col) => {\n // This lets you specify a different element to export as text for the CSV.\n // For example, you may want to export a link but show a download icon in the UI instead.\n // Elements with this class should add the `display-none` class in the UI.\n //\n // Keep in mind that this is optional and only needed if you want to override the default\n // of exporting the text content of the cell.\n let textContainer = col.querySelector('.csv-export-text') || col\n\n rowData.push('\"' + textContainer.innerText + '\"')\n })\n\n csvData.push(rowData.join(','))\n })\n\n return csvData.join('\\n')\n}\n\nwindow.exportTableToCSV = exportTableToCSV\n"],"names":["exportTableToCSV","tableIdentifier","filename","table","stringifiedCSVData","tableToCSVData","csvFile","downloadLink","csvData","row","rowData","col","textContainer"],"mappings":"AAAO,MAAMA,EAAmB,CAACC,EAAiBC,EAAW,eAAiB,CAC5E,MAAMC,EAAQ,SAAS,cAAcF,CAAe,EAEpD,GAAIE,EAAO,CACT,MAAMC,EAAqBC,EAAeF,CAAK,EACzCG,EAAU,IAAI,KAAK,CAACF,CAAkB,EAAG,CAAE,KAAM,UAAY,CAAA,EAEnE,IAAIG,EAAe,SAAS,cAAc,GAAG,EAC7CA,EAAa,SAAWL,EACxBK,EAAa,KAAO,OAAO,IAAI,gBAAgBD,CAAO,EACtDC,EAAa,MAAM,QAAU,OAC7B,SAAS,KAAK,YAAYA,CAAY,EAEtCA,EAAa,MAAK,EAElB,SAAS,KAAK,YAAYA,CAAY,CAC1C,CACA,EAEMF,EAAkBF,GAAU,CAChC,IAAIK,EAAU,CAAA,EAGd,OAFaL,EAAM,iBAAiB,IAAI,EAEnC,QAASM,GAAQ,CACpB,IAAIC,EAAU,CAAA,EACDD,EAAI,iBAAiB,QAAQ,EAErC,QAASE,GAAQ,CAOpB,IAAIC,EAAgBD,EAAI,cAAc,kBAAkB,GAAKA,EAE7DD,EAAQ,KAAK,IAAME,EAAc,UAAY,GAAG,CACjD,CAAA,EAEDJ,EAAQ,KAAKE,EAAQ,KAAK,GAAG,CAAC,CAC/B,CAAA,EAEMF,EAAQ,KAAK;AAAA,CAAI,CAC1B,EAEA,OAAO,iBAAmBR"}