Files
med-notes/.pnpm-store/v10/files/ec/1f5532879e2986868ebb89a19375cbb06d5efa34149d82fe57bd6135a3d14ff82d0dcc33d065680862158d1e7e31333e4f6d07a3e5d5d2b9a7cba33fcf7ed8
2025-05-09 05:30:08 +02:00

46 lines
1.1 KiB
Plaintext

import { useMemo } from 'react';
import {
getAttributes,
isStructTreeNode,
isStructTreeNodeWithOnlyContentChild,
} from './shared/structTreeUtils.js';
import type { StructTreeContent } from 'pdfjs-dist/types/src/display/api.js';
import type { StructTreeNodeWithExtraAttributes } from './shared/types.js';
type StructTreeItemProps = {
className?: string;
node: StructTreeNodeWithExtraAttributes | StructTreeContent;
};
export default function StructTreeItem({
className,
node,
}: StructTreeItemProps): React.ReactElement {
const attributes = useMemo(() => getAttributes(node), [node]);
const children = useMemo(() => {
if (!isStructTreeNode(node)) {
return null;
}
if (isStructTreeNodeWithOnlyContentChild(node)) {
return null;
}
return node.children.map((child, index) => {
return (
// biome-ignore lint/suspicious/noArrayIndexKey: index is stable here
<StructTreeItem key={index} node={child} />
);
});
}, [node]);
return (
<span className={className} {...attributes}>
{children}
</span>
);
}