MCPcopy Index your code
hub / github.com/Alphanimble/htmlstream / patchTableRows

Function patchTableRows

src/patch-streaming-html.ts:705–797  ·  view source on GitHub ↗
(
  container: HTMLElement,
  displayHtml: string,
  track: string,
  prefix: string,
)

Source from the content-addressed store, hash-verified

703}
704
705function patchTableRows(
706 container: HTMLElement,
707 displayHtml: string,
708 track: string,
709 prefix: string,
710): boolean {
711 const table = findActiveTable(container);
712 if (!table) {
713 return false;
714 }
715
716 if (!table.dataset.shLayoutFixed) {
717 table.style.tableLayout = "fixed";
718 table.dataset.shLayoutFixed = "1";
719 }
720
721 seedRowCountsFromDom(table);
722
723 const tableSection = track.slice(prefix.length);
724 const parts = splitTableStream(tableSection);
725
726 // Multiple <tr> opens with no </tr> in track — incremental append duplicates rows.
727 const rowOpens = (tableSection.match(/<tr\b/gi) ?? []).length;
728 if (
729 !/<\/tr>/i.test(tableSection) &&
730 rowOpens >= 2 &&
731 parts.tbodyComplete.length === 0 &&
732 parts.theadComplete.length === 0 &&
733 (parts.tbodyPartial || parts.theadPartial)
734 ) {
735 return false;
736 }
737
738 let thead = table.querySelector("thead");
739 if (!thead) {
740 thead = document.createElement("thead");
741 table.insertBefore(thead, table.firstChild);
742 }
743
744 let tbody = table.querySelector("tbody");
745 if (!tbody) {
746 tbody = document.createElement("tbody");
747 table.appendChild(tbody);
748 }
749
750 // Drop header rows mistakenly patched into tbody during early stream frames
751 if (parts.theadComplete.length > 0) {
752 let removed = false;
753 tbody.querySelectorAll("tr").forEach((tr) => {
754 if (tr.querySelector("th")) {
755 tr.remove();
756 removed = true;
757 }
758 });
759 if (removed) {
760 table.dataset.shRowCount = String(countBodyRows(tbody));
761 }
762 }

Callers 1

patchFirstTableStreamFunction · 0.85

Calls 8

findActiveTableFunction · 0.85
seedRowCountsFromDomFunction · 0.85
splitTableStreamFunction · 0.85
countBodyRowsFunction · 0.85
promoteOrAppendRowsFunction · 0.85
removePartialRowFunction · 0.85
patchPartialRowInSectionFunction · 0.85
syncStreamingCaretFunction · 0.85

Tested by

no test coverage detected