MCPcopy Create free account
hub / github.com/experdot/pointer / TreeView

Function TreeView

src/renderer/src/components/common/TreeView.tsx:331–863  ·  view source on GitHub ↗
({
  items,
  folders,
  selectedId,
  onSelect,
  itemIcon,
  getItemName,
  getFolderName = (f) => f.name,
  isItem,
  batchUpdateItemsOrder,
  updateItem,
  deleteItem,
  updateFolder,
  deleteFolder,
  clearFolder,
  toggleFolderExpanded,
  onDoubleClick,
  getItemMenuItems,
  getFolderMenuItems,
  onGenerateItemName,
  onCreateItemInFolder,
  onCreateSubFolder,
  createItemLabel,
  createFolderLabel,
  highlightId,
  emptyText = '暂无数据',
  className = '',
  checkable = false,
  checkedKeys = [],
  onCheck
}: TreeViewProps<TItem, TFolder>)

Source from the content-addressed store, hash-verified

329// ==================== 组件实现 ====================
330
331export function TreeView<TItem extends ItemLike, TFolder extends FolderLike>({
332 items,
333 folders,
334 selectedId,
335 onSelect,
336 itemIcon,
337 getItemName,
338 getFolderName = (f) => f.name,
339 isItem,
340 batchUpdateItemsOrder,
341 updateItem,
342 deleteItem,
343 updateFolder,
344 deleteFolder,
345 clearFolder,
346 toggleFolderExpanded,
347 onDoubleClick,
348 getItemMenuItems,
349 getFolderMenuItems,
350 onGenerateItemName,
351 onCreateItemInFolder,
352 onCreateSubFolder,
353 createItemLabel,
354 createFolderLabel,
355 highlightId,
356 emptyText = '暂无数据',
357 className = '',
358 checkable = false,
359 checkedKeys = [],
360 onCheck
361}: TreeViewProps<TItem, TFolder>): React.JSX.Element {
362 const { showDeleteConfirm } = useConfirmDialog()
363 const [editingId, setEditingId] = useState<string | null>(null)
364 const [editingValue, setEditingValue] = useState('')
365 const [activeTreeKey, setActiveTreeKey] = useState<string | null>(selectedId)
366
367 // 虚拟滚动:监听容器高度变化
368 const containerRef = useRef<HTMLDivElement>(null)
369 const treeRef = useRef<React.ComponentRef<typeof Tree>>(null)
370 const lastSelectedIdRef = useRef<string | null>(null)
371 const [treeHeight, setTreeHeight] = useState<number | undefined>(undefined)
372
373 useEffect(() => {
374 const container = containerRef.current
375 if (!container) return
376
377 const updateHeight = (): void => {
378 const height = container.clientHeight
379 setTreeHeight(height > 0 ? height : undefined)
380 }
381
382 // 初始化高度
383 updateHeight()
384
385 // 监听容器大小变化
386 const resizeObserver = new ResizeObserver(updateHeight)
387 resizeObserver.observe(container)
388

Callers

nothing calls this directly

Calls 11

useConfirmDialogFunction · 0.90
updateHeightFunction · 0.85
toggleFolderExpandedFunction · 0.85
buildItemNodeFunction · 0.85
buildFolderNodeFunction · 0.85
updateFolderFunction · 0.85
showDeleteConfirmFunction · 0.85
deleteFolderFunction · 0.85
getRootItemsFunction · 0.70
getContextMenuItemsFunction · 0.70
isItemFunction · 0.50

Tested by

no test coverage detected