mirror of
https://ghproxy.cflmy.top/https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-11-30 17:19:35 +08:00
master 通过 #7700 将 portal 菜单改为 CSS Anchor Positioning,并删除了 `useAnchoredPosition`。本次合并让子菜单跟进同一机制: - 子卡片以父卡片内一个不随列表滚动、与卡片同尺寸的锚点框为默认锚点, 侧开时默认在右侧、放不下时由 CSS 翻到左侧;单面板模式占据父卡片位置。 - JavaScript 只决定侧开或单面板,并提供当前行在父卡片内的偏移和子卡片 自然高度;两者都是相对尺寸,双指缩放与平移由 CSS 锚点处理。 - 锚点框绕开了 WebKit 的两个问题:锚定到自身由锚点定位的父卡片时不会 在其定位稳定后重新计算;锚定到滚动列表内的行时不计入滚动偏移。 - 删除 `useAnchoredPosition` 及其测试;`menu-submenu-position` 只保留 侧开/单面板判断,相应单测改为验证模式与锚点名。 - 解决 README、测试与 package.json 冲突,沿用 master 的 CSS 锚点说明并 补充子菜单定位描述。
52 lines
2.8 KiB
TypeScript
52 lines
2.8 KiB
TypeScript
/** Portaled child menu presentation; interaction state belongs to useMenuSubmenu. */
|
|
import type { CSSProperties, ReactNode } from 'react'
|
|
import { createPortal } from 'react-dom'
|
|
import clsx from 'clsx'
|
|
import { menuHoverAllowed, type useMenuSubmenu } from './useMenuSubmenu.ts'
|
|
import { menuIconColumns, MenuRow, renderMenuDecoration } from './MenuRow.tsx'
|
|
import { IconChevronLeftOutlineRegular } from './icons/index.tsx'
|
|
import { MenuSurface } from './MenuSurface.tsx'
|
|
import css from './Menu.module.css'
|
|
|
|
/** Name the parent card anchor, and hide the child card until its layout is known. */
|
|
function anchors(submenu: ReturnType<typeof useMenuSubmenu>, hidden: boolean): CSSProperties & Record<`--dsh-submenu-${string}`, string> {
|
|
return { '--dsh-submenu-parent': submenu.parentAnchor, ...hidden ? { visibility: 'hidden' } : {} }
|
|
}
|
|
|
|
/** Render one child list with a non-selecting back row in single-page placement.
|
|
* @param props - active entry, submenu operations, and shared row presentation options.
|
|
* @returns a body portal that preserves child DOM identity across placement changes.
|
|
*/
|
|
export function SubmenuPanel({ entry, submenu, compact, dense, contextual, backLabel, onSelect, onClose, afterSelection }: {
|
|
entry: NonNullable<ReturnType<typeof useMenuSubmenu>['entry']>
|
|
submenu: ReturnType<typeof useMenuSubmenu>
|
|
compact: boolean
|
|
dense: boolean
|
|
contextual: boolean
|
|
backLabel: ReactNode
|
|
onSelect: ((id: string) => void) | undefined
|
|
onClose: () => void
|
|
afterSelection: () => void
|
|
}) {
|
|
const columns = menuIconColumns(entry.submenu, contextual)
|
|
return createPortal(<MenuSurface ref={submenu.panelRef} compact={compact}
|
|
className={clsx(css.submenu, css.scrollable, dense && css.denseList, compact && css.compactList)}
|
|
style={anchors(submenu, submenu.hidden)}
|
|
data-submenu-layout={submenu.measured ? submenu.page ? 'page' : 'side' : undefined}
|
|
data-contextual={contextual ? '' : undefined} role="menu" onPointerEnter={submenu.cancelClose}
|
|
onPointerLeave={(event) => { if (menuHoverAllowed(event)) submenu.leave() }}
|
|
onContextMenu={contextual ? (event) => { event.preventDefault(); event.stopPropagation(); onClose() } : undefined}
|
|
onClick={(event) => { event.stopPropagation(); afterSelection() }}>
|
|
{submenu.page && <>
|
|
<MenuRow data-menu-back="" icon={<IconChevronLeftOutlineRegular className={css.check} />}
|
|
onClick={submenu.returnToParent}>{backLabel}</MenuRow>
|
|
<div className={css.separator} role="separator" />
|
|
</>}
|
|
<div className={css.viewport} role="presentation">
|
|
{entry.submenu.map(sub => 'type' in sub ? renderMenuDecoration(sub)
|
|
: <MenuRow key={sub.id} icon={sub.icon} reserveIcon={columns.has(sub)} disabled={sub.disabled}
|
|
danger={sub.danger} shortcut={sub.shortcut} onClick={() => { onSelect?.(sub.id) }}>{sub.label}</MenuRow>)}
|
|
</div>
|
|
</MenuSurface>, document.body)
|
|
}
|