From 75cc9b432bc293c01be10173eded41e686bae9b3 Mon Sep 17 00:00:00 2001 From: Cats Juice Date: Thu, 31 Jul 2025 16:09:11 +0800 Subject: [PATCH] feat(core): open external link in web search result (#13362) ## Summary by CodeRabbit * **New Features** * Search results now include clickable links that open in a new tab when available, improving navigation from AI-generated results. * **Style** * Enhanced visual feedback for linked search results, including updated cursor and hover effects for better user experience. --------- Co-authored-by: Wu Yue --- .../components/ai-tools/tool-result-card.ts | 51 ++++++++++++++++++- .../ai/components/ai-tools/web-search.ts | 3 +- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/packages/frontend/core/src/blocksuite/ai/components/ai-tools/tool-result-card.ts b/packages/frontend/core/src/blocksuite/ai/components/ai-tools/tool-result-card.ts index a61f92622..c255e5a19 100644 --- a/packages/frontend/core/src/blocksuite/ai/components/ai-tools/tool-result-card.ts +++ b/packages/frontend/core/src/blocksuite/ai/components/ai-tools/tool-result-card.ts @@ -6,11 +6,13 @@ import { ToggleDownIcon, ToolIcon } from '@blocksuite/icons/lit'; import { type Signal } from '@preact/signals-core'; import { css, html, nothing, type TemplateResult } from 'lit'; import { property, state } from 'lit/decorators.js'; +import { ifDefined } from 'lit/directives/if-defined.js'; export interface ToolResult { title: string | TemplateResult<1>; icon?: string | TemplateResult<1>; content?: string; + href?: string; } export class ToolResultCard extends SignalWatcher( @@ -18,6 +20,7 @@ export class ToolResultCard extends SignalWatcher( ) { static override styles = css` .ai-tool-result-wrapper { + display: block; padding: 12px; margin: 8px 0; border-radius: 8px; @@ -88,6 +91,12 @@ export class ToolResultCard extends SignalWatcher( .result-item { margin-top: 16px; + display: block; + cursor: default; + } + + .result-item[href] { + cursor: pointer; } .result-item:first-child { @@ -144,6 +153,37 @@ export class ToolResultCard extends SignalWatcher( } } + .result-item[href]:hover .result-title, + .result-item[href]:hover .result-content { + color: ${unsafeCSSVarV2('text/primary')}; + } + + .result-icon, + .footer-icon { + width: 18px; + height: 18px; + border-radius: 100%; + background-color: ${unsafeCSSVarV2('layer/background/primary')}; + + img { + width: 18px; + height: 18px; + border-radius: 100%; + border: 0.5px solid ${unsafeCSSVarV2('layer/insideBorder/border')}; + } + + svg { + width: 18px; + height: 18px; + color: ${unsafeCSSVarV2('icon/primary')}; + } + } + + .result-item[href]:hover .result-title, + .result-item[href]:hover .result-content { + color: ${unsafeCSSVarV2('text/primary')}; + } + .footer-icons { display: flex; position: relative; @@ -202,7 +242,14 @@ export class ToolResultCard extends SignalWatcher(
${this.results.map( result => html` - diff --git a/packages/frontend/core/src/blocksuite/ai/components/ai-tools/web-search.ts b/packages/frontend/core/src/blocksuite/ai/components/ai-tools/web-search.ts index 2f51c63e1..83ae12cec 100644 --- a/packages/frontend/core/src/blocksuite/ai/components/ai-tools/web-search.ts +++ b/packages/frontend/core/src/blocksuite/ai/components/ai-tools/web-search.ts @@ -56,11 +56,12 @@ export class WebSearchTool extends WithDisposable(ShadowlessElement) { const result = this.data.result; if (result && Array.isArray(result)) { const results = result.map(item => { - const { favicon, title, content } = item; + const { favicon, title, content, url } = item; return { title: title, icon: favicon || WebIcon(), content: content, + href: url, }; }); const footerIcons = result.map(item => item.favicon).filter(Boolean);