@@ -287,17 +287,28 @@ export function readHtmlRenderContentHeight(data: unknown): number | undefined {
287287 return typeof height === "number" && Number . isFinite ( height ) && height > 0 ? height : undefined ;
288288}
289289
290- /** A render's `ui/open-link` request, if `data` is one with an http(s) URL. */
291- export function readHtmlRenderLinkRequest (
292- data : unknown ,
293- ) : { readonly id : string | number ; readonly url : string } | undefined {
290+ /**
291+ * A render's `ui/open-link` request, if `data` is one with an http(s) URL. The
292+ * bootstrap adds the click's Cmd/Ctrl state, so a modifier click can leave the
293+ * app the way it does from a chat link.
294+ */
295+ export function readHtmlRenderLinkRequest ( data : unknown ) :
296+ | {
297+ readonly id : string | number ;
298+ readonly url : string ;
299+ readonly metaKey : boolean ;
300+ readonly ctrlKey : boolean ;
301+ }
302+ | undefined {
294303 if ( typeof data !== "object" || data === null ) return undefined ;
295304 const { jsonrpc, id, method, params } = data as Record < string , unknown > ;
296305 if ( jsonrpc !== "2.0" || method !== OPEN_LINK_METHOD ) return undefined ;
297306 if ( typeof id !== "string" && typeof id !== "number" ) return undefined ;
298- const url =
299- typeof params === "object" && params !== null ? ( params as { url ?: unknown } ) . url : undefined ;
300- return typeof url === "string" && / ^ h t t p s ? : \/ \/ / i. test ( url ) ? { id, url } : undefined ;
307+ if ( typeof params !== "object" || params === null ) return undefined ;
308+ const { url, metaKey, ctrlKey } = params as Record < string , unknown > ;
309+ return typeof url === "string" && / ^ h t t p s ? : \/ \/ / i. test ( url )
310+ ? { id, url, metaKey : metaKey === true , ctrlKey : ctrlKey === true }
311+ : undefined ;
301312}
302313
303314/** The empty result a client sends back for a render's request. */
@@ -345,7 +356,7 @@ function rootRule(theme: HtmlRenderTheme): string {
345356// opens it as a new window, which the client sends to the browser. A framed
346357// page also reports its content height, measured as the server measures it,
347358// so its client can fit the frame to the page.
348- const BOOTSTRAP_SCRIPT = `(function(){var s=document.getElementById("t3-theme"),n=0;if(!s)return;var b=${ JSON . stringify ( BASE_CSS ) } ;function a(t){if(!t||typeof t!=="object"||!t.variables||typeof t.variables!=="object")return;var c=":root{color-scheme:"+(t.appearance==="light"?"light":"dark")+";";for(var k in t.variables){if(/^--[a-z0-9-]+$/.test(k))c+=k+":"+String(t.variables[k]).replace(/[;{}<>]/g,"")+";";}s.textContent=c+"}"+b;}try{var m=/[#&]${ THEME_FRAGMENT_KEY } =([^&]*)/.exec(location.hash);if(m){a(JSON.parse(decodeURIComponent(m[1])));history.replaceState(history.state,"",location.pathname+location.search);}}catch(e){}window.addEventListener("message",function(e){var d=e.data,p=d&&d.params;if(d&&d.jsonrpc==="2.0"&&d.method===${ JSON . stringify ( HOST_CONTEXT_CHANGED_METHOD ) } &&p&&p.styles)a({appearance:p.theme,variables:p.styles.variables});});document.addEventListener("click",function(e){var l=e.isTrusted?e.composedPath().find(function(t){return t&&t.matches&&t.matches("a[href]");}):null,u;if(!l)return;try{u=new URL(l.getAttribute("href"),document.baseURI);}catch(x){return;}if(!/^https?:$/.test(u.protocol)||u.href.split("#")[0]===location.href.split("#")[0])return;if(window.parent!==window){e.preventDefault();window.parent.postMessage({jsonrpc:"2.0",id:"t3-link-"+(++n),method:${ JSON . stringify ( OPEN_LINK_METHOD ) } ,params:{url:u.href}},"*");}else{l.setAttribute("target","_blank");l.setAttribute("rel","noopener");}},true);if(window.parent!==window){var h,o,z=function(){var r=document.documentElement,v=Math.ceil(r.scrollHeight>r.clientHeight?r.scrollHeight:r.getBoundingClientRect().height);if(v===h)return;h=v;window.parent.postMessage({jsonrpc:"2.0",method:${ JSON . stringify ( SIZE_CHANGED_METHOD ) } ,params:{height:v}},"*");};if(window.ResizeObserver){o=new ResizeObserver(z);o.observe(document.documentElement);}document.addEventListener("DOMContentLoaded",function(){if(o&&document.body)o.observe(document.body);z();});window.addEventListener("load",z);}})();` ;
359+ const BOOTSTRAP_SCRIPT = `(function(){var s=document.getElementById("t3-theme"),n=0;if(!s)return;var b=${ JSON . stringify ( BASE_CSS ) } ;function a(t){if(!t||typeof t!=="object"||!t.variables||typeof t.variables!=="object")return;var c=":root{color-scheme:"+(t.appearance==="light"?"light":"dark")+";";for(var k in t.variables){if(/^--[a-z0-9-]+$/.test(k))c+=k+":"+String(t.variables[k]).replace(/[;{}<>]/g,"")+";";}s.textContent=c+"}"+b;}try{var m=/[#&]${ THEME_FRAGMENT_KEY } =([^&]*)/.exec(location.hash);if(m){a(JSON.parse(decodeURIComponent(m[1])));history.replaceState(history.state,"",location.pathname+location.search);}}catch(e){}window.addEventListener("message",function(e){var d=e.data,p=d&&d.params;if(d&&d.jsonrpc==="2.0"&&d.method===${ JSON . stringify ( HOST_CONTEXT_CHANGED_METHOD ) } &&p&&p.styles)a({appearance:p.theme,variables:p.styles.variables});});document.addEventListener("click",function(e){var l=e.isTrusted?e.composedPath().find(function(t){return t&&t.matches&&t.matches("a[href]");}):null,u;if(!l)return;try{u=new URL(l.getAttribute("href"),document.baseURI);}catch(x){return;}if(!/^https?:$/.test(u.protocol)||u.href.split("#")[0]===location.href.split("#")[0])return;if(window.parent!==window){e.preventDefault();window.parent.postMessage({jsonrpc:"2.0",id:"t3-link-"+(++n),method:${ JSON . stringify ( OPEN_LINK_METHOD ) } ,params:{url:u.href,metaKey:e.metaKey,ctrlKey:e.ctrlKey}},"*");}else{l.setAttribute("target","_blank");l.setAttribute("rel","noopener");}},true);if(window.parent!==window){var h,o,z=function(){var r=document.documentElement,v=Math.ceil(r.scrollHeight>r.clientHeight?r.scrollHeight:r.getBoundingClientRect().height);if(v===h)return;h=v;window.parent.postMessage({jsonrpc:"2.0",method:${ JSON . stringify ( SIZE_CHANGED_METHOD ) } ,params:{height:v}},"*");};if(window.ResizeObserver){o=new ResizeObserver(z);o.observe(document.documentElement);}document.addEventListener("DOMContentLoaded",function(){if(o&&document.body)o.observe(document.body);z();});window.addEventListener("load",z);}})();` ;
349360
350361function bootstrapMarkup ( markup : string ) : string {
351362 const dark = htmlRenderTheme ( T3_CODE_DARK_THEME_COLORS , "dark" ) ;
0 commit comments