{"version":3,"file":"rtf-BcuPr4VT.js","sources":["../../../../src/scripts/modules/rtf.ts"],"sourcesContent":["import { Component } from '@verndale/core';\n\nclass Rtf extends Component {\n private tableShowMore: string = 'Show More';\n private tableShowLess: string = 'Show Less';\n private tableRows: number = 6;\n\n setupDefaults() {\n this.dom = {\n tables: this.el?.querySelectorAll('table') || []\n };\n }\n\n constructor(el: HTMLElement) {\n super(el);\n this.init();\n }\n\n addListeners() {}\n\n init() {\n const tableShowMore = this.el?.getAttribute('data-label-table-show-more');\n const tableShowLess = this.el?.getAttribute('data-label-table-show-less');\n const tableRows = this.el?.getAttribute('data-table-rows');\n\n if (tableShowMore) {\n this.tableShowMore = tableShowMore;\n }\n\n if (tableShowLess) {\n this.tableShowLess = tableShowLess;\n }\n\n if (tableRows) {\n const parsedRows = parseInt(tableRows, 10);\n if (!isNaN(parsedRows)) {\n this.tableRows = parsedRows;\n }\n }\n\n (this.dom.tables as NodeListOf)?.forEach((table: HTMLTableElement) => {\n this.loadMoreTable(table);\n });\n }\n\n loadMoreTable(table: HTMLTableElement) {\n const rows = table.querySelectorAll('tr');\n const rowsArray = Array.from(rows);\n let rowsWithoutThead = rowsArray.filter(row => !row.closest('thead'));\n\n if (rowsWithoutThead.length > 0 && rowsWithoutThead[0].querySelectorAll('th').length > 0) {\n rowsWithoutThead = rowsWithoutThead.slice(1);\n }\n\n const tableScroll = document.createElement('div');\n tableScroll.classList.add('rtf__table-scroll');\n\n table.parentNode?.insertBefore(tableScroll, table);\n tableScroll.appendChild(table);\n\n if (this.tableRows === 0 || rowsWithoutThead.length <= this.tableRows) return;\n\n const tableWrapper = document.createElement('div');\n tableWrapper.classList.add('rtf__table-wrapper');\n tableScroll.parentNode?.insertBefore(tableWrapper, tableScroll);\n tableWrapper.appendChild(tableScroll);\n\n rowsWithoutThead.forEach((row, index) => {\n if (index >= this.tableRows) {\n row.classList.add('rtf__table-row--hidden');\n }\n });\n\n const showMore = document.createElement('button');\n showMore.setAttribute('type', 'button');\n showMore.classList.add('btn', 'btn--outline', 'table__show-more');\n showMore.textContent = this.tableShowMore;\n tableWrapper.appendChild(showMore);\n\n let isShowingMore = false;\n\n showMore.addEventListener('click', e => {\n e?.preventDefault();\n showMore.blur();\n\n if (isShowingMore) {\n rowsWithoutThead.forEach((row, index) => {\n if (index >= this.tableRows) {\n row.classList.add('rtf__table-row--hidden');\n }\n });\n showMore.textContent = this.tableShowMore;\n } else {\n rowsWithoutThead.forEach(row => {\n row.classList.remove('rtf__table-row--hidden');\n });\n showMore.textContent = this.tableShowLess;\n }\n isShowingMore = !isShowingMore;\n });\n }\n}\n\nexport default Rtf;\n"],"names":["Rtf","Component","el","__publicField","_a","tableShowMore","tableShowLess","_b","tableRows","_c","parsedRows","_d","table","rows","rowsWithoutThead","row","tableScroll","tableWrapper","index","showMore","isShowingMore","e"],"mappings":"iNAEA,MAAMA,UAAYC,CAAU,CAW1B,YAAYC,EAAiB,CAC3B,MAAMA,CAAE,EAXFC,EAAA,qBAAwB,aACxBA,EAAA,qBAAwB,aACxBA,EAAA,iBAAoB,GAU1B,KAAK,KAAK,CAAA,CARZ,eAAgB,OACd,KAAK,IAAM,CACT,SAAQC,EAAA,KAAK,KAAL,YAAAA,EAAS,iBAAiB,WAAY,CAAA,CAChD,CAAA,CAQF,cAAe,CAAA,CAEf,MAAO,aACL,MAAMC,GAAgBD,EAAA,KAAK,KAAL,YAAAA,EAAS,aAAa,8BACtCE,GAAgBC,EAAA,KAAK,KAAL,YAAAA,EAAS,aAAa,8BACtCC,GAAYC,EAAA,KAAK,KAAL,YAAAA,EAAS,aAAa,mBAUxC,GARIJ,IACF,KAAK,cAAgBA,GAGnBC,IACF,KAAK,cAAgBA,GAGnBE,EAAW,CACP,MAAAE,EAAa,SAASF,EAAW,EAAE,EACpC,MAAME,CAAU,IACnB,KAAK,UAAYA,EACnB,EAGDC,EAAA,KAAK,IAAI,SAAT,MAAAA,EAAkD,QAASC,GAA4B,CACtF,KAAK,cAAcA,CAAK,CAAA,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