import { CopyOutlined, CheckCircleTwoTone } from '@ant-design/icons' import { Tooltip, Space, message } from 'antd' import classnames from 'classnames' import ClipboardJS from 'clipboard' import VirtualList from 'rc-virtual-list' import React, { useEffect, useRef, memo } from 'react' import { Link, useParams } from 'react-router-dom' import useBearStore from '@/stores' import { useTagsStore } from '@/stores/persist' import { printBatchOperations } from '@/utils/printBatchOperations' import styles from './index.module.less' import { getDistanceToAncestor, isElementInViewport } from './utils' import type { OperationDefinitionNodeGroupType } from '@fruits-chain/qiufen-pro-helpers' import type { ListRef } from 'rc-virtual-list' import type { FC } from 'react' // 分组大小 const groupCount = 35 const OperationItem = ({ operation, workspaceGqlNames, isMoreExist, switchBothZhEn, active, isMakeVirtual, }: { /** 区分是不是走的虚拟列表模式 */ isMakeVirtual?: boolean operation: OperationDefinitionNodeGroupType active: boolean workspaceGqlNames: string[] isMoreExist: boolean switchBothZhEn: boolean }) => { const { addATags } = useTagsStore() const { id: routeId } = useParams<'id'>() const groupedId = routeId?.split('&')?.[1] || '' useEffect(() => { // 滚动条归属的盒子 const sidebarContent = document.querySelector( '#sidebarContent', ) as HTMLDivElement // 一下是不通过虚拟列表实现的时候滚动条滚到当前激活的item位置 if (active) { // 当前激活的item const activeItm = document.querySelector( `#${operation.operation + operation.name?.value}`, ) as HTMLDivElement requestAnimationFrame(() => { const isInViewRange = isElementInViewport(activeItm, sidebarContent) const topDistance = getDistanceToAncestor(activeItm, sidebarContent) if (!isInViewRange) { // 将滚动条滚到当前被激活的分类标题的位置 sidebarContent?.scrollTo({ top: Math.max(0, topDistance - 300), }) } }) } }, [active]) return ( { const routePath = groupedId ? `/docs/${operation.operation + operation.name?.value}&${groupedId}` : `/docs/${operation.operation + operation.name?.value}` const operationZhCn = getOperationNameValue(operation.operationDefinitionDescription) || '' addATags({ type: operation.operation, operationZhCn: operationZhCn, operation: operation.name?.value ?? '', routePath, }) }} to={ groupedId ? `/docs/${operation.operation + operation.name?.value}&${groupedId}` : `/docs/${operation.operation + operation.name?.value}` }>