-
-
Notifications
You must be signed in to change notification settings - Fork 844
/
StructTreeItem.tsx
42 lines (34 loc) · 1.04 KB
/
StructTreeItem.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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) {
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 (
// eslint-disable-next-line react/no-array-index-key
<StructTreeItem key={index} node={child} />
);
});
}, [node]);
return (
<span className={className} {...attributes}>
{children}
</span>
);
}