MCPcopy Create free account
hub / github.com/CopilotKit/OpenGenerativeUI / tryAttach

Function tryAttach

apps/app/src/components/explainer-cards.tsx:92–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

90 const PORTAL_ID = "explainer-cards-portal";
91
92 const tryAttach = () => {
93 const welcomeScreen = document.querySelector<HTMLElement>(WELCOME_SELECTOR);
94 if (!welcomeScreen) {
95 setPortalTarget(null);
96 return;
97 }
98
99 // Reuse existing portal container if present
100 let portal = document.getElementById(PORTAL_ID);
101 if (portal) {
102 setPortalTarget(portal);
103 return;
104 }
105
106 // Insert portal container inside the welcome screen's main content div,
107 // before the suggestions row
108 const mainContent = welcomeScreen.children[0] as HTMLElement | undefined;
109 if (!mainContent) return;
110
111 portal = document.createElement("div");
112 portal.id = PORTAL_ID;
113 portal.style.width = "100%";
114
115 // Insert before the last child (suggestions row)
116 const suggestionsRow = mainContent.lastElementChild;
117 if (suggestionsRow) {
118 mainContent.insertBefore(portal, suggestionsRow);
119 } else {
120 mainContent.appendChild(portal);
121 }
122
123 setPortalTarget(portal);
124 };
125
126 tryAttach();
127

Callers 1

ExplainerCardsPortalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected