Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions web/src/components/home-edit-board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ import type { LinkStyle, SiteCategory, SiteLink } from "@/lib/types";
*
* 触屏:`TouchSensor` 长按 250ms 才激活(普通滑动照常滚动页面),`MouseSensor`
* 位移 6px 激活(单击不被吃掉)。拖拽覆盖层用 dnd-kit 原生 `DragOverlay`。
*
* 尺寸口径(2026-11-08):砖的格子由 `LINK_GRID_CLASS` 给出(与普通模式同一个网格),
* 砖壳必须 **撑满格子** —— `<button>` 的 `width: auto` 在 Chrome 里按内容收缩,
* 不补 `w-full` 的话长名称/长网址的砖会比旁边的宽、甚至溢出格子。撑满后名称与网址
* 单行截断(`LinkTileContent` 的 `singleLine`)、悬停 `title` 看全称,同档砖因此
* 同宽同高;✕ 角标定位在外层格子 div 上,自然落在砖的右上角。拖拽预览用
* dnd-kit 的 `DragOverlay`:包裹层尺寸由它按砖的实测矩形给定,砖规整后预览也就一致。
*/

/** 分类标题行投放目标(落到该分类末尾)的 id 前缀 */
Expand All @@ -69,11 +76,15 @@ const collisionDetection: CollisionDetection = (args) => {
return endTarget ? [endTarget] : closestCorners(args);
};

/** 空分类占位的高度:与同档一块砖一致(虚线框内不写字) */
/**
* 空分类占位的高度:与同档一块砖一致(虚线框内不写字)——实测值,砖壳撑满格子后
* 三档分别落在 130 / 36 / 62px(classic 图标 44 + 名称与网址各一行;compact 小图标
* 单行;wide 图标 36 一行名称 + 一行域名),占位框随之对齐。
*/
const PLACEHOLDER_CLASS: Record<LinkStyle, string> = {
classic: "min-h-[132px]",
compact: "min-h-11",
wide: "min-h-[60px]",
classic: "min-h-[130px]",
compact: "min-h-9",
wide: "min-h-[62px]",
};

type Order = Record<string, string[]>;
Expand Down Expand Up @@ -194,13 +205,15 @@ function EditableTile({
{...attributes}
{...listeners}
aria-label={link.title}
title={link.title}
className={cn(
linkTileClassName(linkStyle),
"cursor-grab select-none active:cursor-grabbing",
// 撑满网格格子(与普通模式的 `<a>` 同宽),名称/网址在砖内截断省略号
"w-full min-w-0 cursor-grab select-none active:cursor-grabbing",
)}
onClick={() => onEdit(link.id)}
>
<LinkTileContent link={link} linkStyle={linkStyle} />
<LinkTileContent link={link} linkStyle={linkStyle} singleLine />
</button>
<button
type="button"
Expand Down Expand Up @@ -451,7 +464,11 @@ export function HomeEditBoard({
"cursor-grabbing shadow-2xl",
)}
>
<LinkTileContent link={activeLink} linkStyle={linkStyle} />
<LinkTileContent
link={activeLink}
linkStyle={linkStyle}
singleLine
/>
</div>
) : null}
</DragOverlay>
Expand Down
55 changes: 45 additions & 10 deletions web/src/components/link-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FadeIn, GlassCard } from "@/components/glass";
import { SiteIcon } from "@/components/site-icon";
import { safeHost } from "@/lib/icons";
import type { LinkStyle, SiteCategory, SiteLink } from "@/lib/types";
import { cn } from "@/lib/utils";

/**
* 链接网格(站点设置 `linkStyle` 决定呈现形态,全站统一、访客不可切)。
Expand All @@ -20,8 +21,9 @@ import type { LinkStyle, SiteCategory, SiteLink } from "@/lib/types";
*
* 首页编辑模式(home-edit-board.tsx)复用同一套「砖的外观」:`linkTileClassName`
* 给出三档外壳类、`LinkTileContent` 给出内层 DOM(图标 / 名称 / 域名)。正常模式
* 仍把外壳挂在 `<a>` 上、DOM 与类名保持改动前一致;编辑模式把它挂在一个
* `role="button"` 的 `<div>` 上(单击打开编辑弹窗,不跳转)。
* 仍把外壳挂在 `<a>` 上、DOM 与类名保持改动前一致;编辑模式把它挂在一个撑满网格
* 格子的 `<button>` 上(单击打开编辑弹窗,不跳转),并传 `singleLine` 让名称与网址
* 各占一行、超长截断省略号(悬停 `title` 看全称)。
*/

/** 每档的网格列数(只有列数与间距不同,条目形状见下方各自的组件)。 */
Expand All @@ -47,17 +49,33 @@ export function linkTileClassName(linkStyle: LinkStyle): string {
return "glass glass-hover group flex h-full flex-col items-center gap-2 rounded-2xl px-2 py-4 text-center";
}

/** 砖的内层内容(不含外壳):三档各自的图标尺寸、名称与域名排布。 */
/**
* 砖的内层内容(不含外壳):三档各自的图标尺寸、名称与域名排布。
*
* `singleLine`:编辑模式的砖宽高由网格给定(home-edit-board.tsx 把外壳撑满格子),
* 名称与网址各占一行、超长截断省略号,并补 `title` 让悬停可看全称;普通模式的砖
* 仍按改动前的排布(classic 名称最多两行),不传该 prop 即可。
*
* `showUrl`:普通模式的「显示网址」开关(站点设置 `showUrl`);编辑模式不传,恒显示。
*/
export function LinkTileContent({
link,
linkStyle,
singleLine = false,
showUrl = true,
}: {
link: SiteLink;
linkStyle: LinkStyle;
/** 名称单行截断 + 名称/网址补 title(编辑模式用;普通模式保持原排布) */
singleLine?: boolean;
/** 是否渲染网址行(站点设置 `showUrl`);编辑模式不传,恒显示 */
showUrl?: boolean;
}) {
const host = safeHost(link.url);
// 只在编辑模式补 title:普通模式的 DOM 与提示行为保持改动前一致
const titleAttr = singleLine ? link.title : undefined;
const hostAttr = singleLine ? host : undefined;

if (linkStyle === "compact") {
return (
<>
Expand All @@ -67,7 +85,9 @@ export function LinkTileContent({
iconUrl={link.iconUrl}
size={20}
/>
<span className="min-w-0 flex-1 truncate text-sm">{link.title}</span>
<span title={titleAttr} className="min-w-0 flex-1 truncate text-sm">
{link.title}
</span>
</>
);
}
Expand All @@ -81,12 +101,18 @@ export function LinkTileContent({
size={36}
/>
<span className="min-w-0 flex-1">
<span className="block truncate text-sm font-medium text-foreground/90">
<span
title={titleAttr}
className="block truncate text-sm font-medium text-foreground/90"
>
{link.title}
</span>
{showUrl && (
<span className="block truncate text-xs text-muted-foreground">
{safeHost(link.url)}
<span
title={hostAttr}
className="block truncate text-xs text-muted-foreground"
>
{host}
</span>
)}
</span>
Expand All @@ -101,12 +127,21 @@ export function LinkTileContent({
iconUrl={link.iconUrl}
size={44}
/>
<span className="line-clamp-2 w-full text-sm font-medium text-foreground/90">
<span
title={titleAttr}
className={cn(
"w-full text-sm font-medium text-foreground/90",
singleLine ? "truncate" : "line-clamp-2",
)}
>
{link.title}
</span>
{showUrl && (
<span className="w-full truncate text-xs text-muted-foreground">
{safeHost(link.url)}
<span
title={hostAttr}
className="w-full truncate text-xs text-muted-foreground"
>
{host}
</span>
)}
</>
Expand Down
Loading