feat(grid): open cell http urls from hover overlay

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-09-03 11:56:58 +08:00
1 parent aa4f503353
commit ef13dc024f
13 files changed
+92 -13

No files matched your search

@@ -198,14 +198,14 @@ export function fitCanvasText(ctx: CanvasRenderingContext2D, text: string, maxWi
return result;
}
export function canvasDataGridActionReservedWidth(canQuickDownload: boolean, canNavigateForeignKey = false, showCellDetail = true): number {
const overlayWidth = canvasDataGridActionOverlayWidth(canQuickDownload, canNavigateForeignKey, showCellDetail);
export function canvasDataGridActionReservedWidth(canQuickDownload: boolean, canNavigateForeignKey = false, showCellDetail = true, canOpenExternalUrl = false): number {
const overlayWidth = canvasDataGridActionOverlayWidth(canQuickDownload, canNavigateForeignKey, showCellDetail, canOpenExternalUrl);
return overlayWidth > 0 ? overlayWidth + 6 : 0;
}
/** 悬浮按钮组宽度:每个已启用按钮 20px + 2px 间距。 */
export function canvasDataGridActionOverlayWidth(canQuickDownload: boolean, canNavigateForeignKey = false, showCellDetail = true): number {
return (showCellDetail ? 22 : 0) + (canQuickDownload ? 22 : 0) + (canNavigateForeignKey ? 22 : 0);
export function canvasDataGridActionOverlayWidth(canQuickDownload: boolean, canNavigateForeignKey = false, showCellDetail = true, canOpenExternalUrl = false): number {
return (showCellDetail ? 22 : 0) + (canQuickDownload ? 22 : 0) + (canNavigateForeignKey ? 22 : 0) + (canOpenExternalUrl ? 22 : 0);
}
export function resolveCanvasCellTextLayout(options: { drawX: number; colWidth: number; dpr: number; isRightAlign: boolean; reservedWidth?: number }): { textAnchorX: number; maxWidth: number } {
@@ -0,0 +1,18 @@
import type { CellValue } from "@/lib/dataGrid/cellValue";
/** Return a browser-safe external URL only when the whole cell is an HTTP(S) URL. */
export function cellExternalUrl(value: CellValue | unknown): string | null {
if (typeof value !== "string") return null;
const text = value.trim();
if (!text) return null;
let parsed: URL;
try {
parsed = new URL(text);
} catch {
return null;
}
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
return text;
}