Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import type { FC } from "react";
import { getType } from "mobx-state-tree";
import { observer } from "mobx-react";
import { ApartmentOutlined, AudioOutlined, LineChartOutlined, MessageOutlined } from "@ant-design/icons";
 
import Registry from "../../core/Registry";
import "./Node.scss";
import {
  IconBrushTool,
  IconBrushToolSmart,
  IconCircleTool,
  IconCircleToolSmart,
  IconKeypointsTool,
  IconKeypointsToolSmart,
  IconPolygonTool,
  IconPolygonToolSmart,
  IconRectangle3PointTool,
  IconRectangle3PointToolSmart,
  IconRectangleTool,
  IconRectangleToolSmart,
  IconText,
  IconTimelineRegion,
} from "@humansignal/icons";
 
interface NodeViewProps {
  name: string;
  icon: any;
  altIcon?: any;
  getContent?: (node: any) => JSX.Element | null;
  fullContent?: (node: any) => JSX.Element | null;
}
 
const NodeViews: Record<string, NodeViewProps> = {
  // fake view for virtual node representing label group
  LabelModel: {
    name: "",
    icon: () => null,
  },
 
  RichTextRegionModel: {
    name: "HTML",
    icon: IconText,
    getContent: (node: any) => <span style={{ color: "#5a5a5a" }}>{node.text}</span>,
    fullContent: (node: any) => (
      <div>
        {/* <div style={{ color: "#5a5a5a" }}>{node.text}</div> */}
        <div>{node.start}</div>
        <div>{node.startOffset}</div>
        <div>{JSON.stringify(node.globalOffsets, null, 2)}</div>
      </div>
    ),
  },
 
  ParagraphsRegionModel: {
    name: "Paragraphs",
    icon: IconText,
    getContent: (node) => <span style={{ color: "#5a5a5a" }}>{node.text}</span>,
  },
 
  AudioRegionModel: {
    name: "Audio",
    icon: AudioOutlined,
  },
 
  TimeSeriesRegionModel: {
    name: "TimeSeries",
    icon: LineChartOutlined,
  },
 
  TextAreaRegionModel: {
    name: "Input",
    icon: MessageOutlined,
    getContent: (node) => <span style={{ color: "#5a5a5a" }}>{node._value}</span>,
  },
 
  RectRegionModel: {
    name: "Rect",
    icon: IconRectangleTool,
    altIcon: IconRectangleToolSmart,
  },
 
  Rect3PointRegionModel: {
    name: "Rect3Point",
    icon: IconRectangle3PointTool,
    altIcon: IconRectangle3PointToolSmart,
  },
 
  VideoRectangleRegionModel: {
    name: "Video Rect",
    icon: IconRectangleTool,
    altIcon: IconRectangleToolSmart,
    getContent: (node) => <span style={{ color: "#5a5a5a" }}>from {node.sequence[0]?.frame} frame</span>,
  },
 
  PolygonRegionModel: {
    name: "Polygon",
    icon: IconPolygonTool,
    altIcon: IconPolygonToolSmart,
  },
 
  VectorRegionModel: {
    name: "Vector",
    icon: IconPolygonTool,
    altIcon: IconPolygonToolSmart,
  },
 
  EllipseRegionModel: {
    name: "Ellipse",
    icon: IconCircleTool,
    altIcon: IconCircleToolSmart,
  },
 
  // @todo add coords
  KeyPointRegionModel: {
    name: "KeyPoint",
    icon: IconKeypointsTool,
    altIcon: IconKeypointsToolSmart,
  },
 
  BrushRegionModel: {
    name: "Brush",
    icon: IconBrushTool,
    altIcon: IconBrushToolSmart,
  },
 
  BitmaskRegionModel: {
    name: "Brush",
    icon: IconBrushTool,
    altIcon: IconBrushToolSmart,
  },
 
  ChoicesModel: {
    name: "Classification",
    icon: ApartmentOutlined,
  },
 
  TextAreaModel: {
    name: "Input",
    icon: MessageOutlined,
  },
 
  TimelineRegionModel: {
    name: "Timeline Span",
    icon: IconTimelineRegion,
  },
 
  ...Object.fromEntries(
    Registry.customTags.filter((tag) => tag.region).map((tag) => [tag.region.name, tag.region.nodeView]),
  ),
};
 
const NodeIcon: FC<any> = observer(({ node, ...props }) => {
  const name = useNodeName(node);
 
  if (!name || !(name in NodeViews)) {
    console.error(`No ${name} in NodeView`);
    return null;
  }
 
  const { icon: Icon } = NodeViews[name];
 
  return <Icon {...props} />;
});
 
const useNodeName = (node: any) => {
  // @todo sometimes node is control tag, not a region
  // @todo and for new taxonomy it can be plain object
  if (!node.$treenode) return null;
  return getType(node).name as keyof typeof NodeViews;
};
 
export { NodeIcon, NodeViews };