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

Function patchStreamingHtml

src/patch-streaming-html.ts:585–665  ·  view source on GitHub ↗
(
  container: HTMLElement,
  displayHtml: string,
  trackClean: string,
  previousTrack: string,
)

Source from the content-addressed store, hash-verified

583 * Returns true if patched in-place, false if caller should full replace.
584 */
585export function patchStreamingHtml(
586 container: HTMLElement,
587 displayHtml: string,
588 trackClean: string,
589 previousTrack: string,
590): boolean {
591 const track = stripCaret(trackClean);
592 if (track === previousTrack) {
593 return true;
594 }
595
596 const tableStart = findTableStart(track);
597 const prevTableStart = findTableStart(previousTrack);
598
599 // Table just started — append prefix then patch the table tail
600 if (tableStart !== -1 && prevTableStart === -1) {
601 const prefix = track.slice(0, tableStart);
602 if (prefix.startsWith(previousTrack) || previousTrack.startsWith(prefix)) {
603 if (prefix.length > previousTrack.length) {
604 container.insertAdjacentHTML(
605 "beforeend",
606 prefix.slice(previousTrack.length),
607 );
608 }
609 if (container.querySelector("table")) {
610 return patchFirstTableStream(
611 container,
612 displayHtml,
613 track,
614 previousTrack,
615 );
616 }
617 }
618 return false;
619 }
620
621 // Table streaming — append rows instead of replacing the whole table
622 if (
623 tableStart !== -1 &&
624 prevTableStart !== -1 &&
625 tableStart === prevTableStart
626 ) {
627 const prefix = track.slice(0, tableStart);
628 const prevPrefix = previousTrack.slice(0, prevTableStart);
629
630 if (prefix === prevPrefix) {
631 return patchFirstTableStream(
632 container,
633 displayHtml,
634 track,
635 previousTrack,
636 );
637 }
638 }
639
640 // Plain text only — append into open element or container root
641 if (
642 tableStart === -1 &&

Callers 4

streamhtml.tsxFile · 0.90
patchPostTableTailFunction · 0.85

Calls 9

appendStreamingTextChunkFunction · 0.90
findTableStartFunction · 0.85
patchFirstTableStreamFunction · 0.85
isTextOnlySuffixFunction · 0.85
getOpenTagStackFunction · 0.85
findDeepOpenElementFunction · 0.85
syncStreamingCaretFunction · 0.85
stripCaretFunction · 0.70

Tested by

no test coverage detected