1
- import { useState , useEffect } from 'react' ;
1
+ import { useState , useEffect , useRef } from 'react' ;
2
2
import type { Chain } from '@/../script/index' ;
3
3
import { chainLogoUrl , classNames } from '@/lib/utils' ;
4
4
import { ExternalLink } from '@/components/layout/ExternalLink' ;
@@ -9,7 +9,7 @@ import { Copyable } from '@/components/ui/Copyable';
9
9
import { evmStackAddresses , type EVMStackResult } from '@/../script/checks/evm-stack-addresses' ;
10
10
import { knownOpcodes } from '@/../script/checks/opcodes' ;
11
11
import { getAddress } from 'viem' ;
12
- import { ArrowTopRightOnSquareIcon } from '@heroicons/react/20/solid' ;
12
+ import { ArrowTopRightOnSquareIcon , LinkIcon } from '@heroicons/react/20/solid' ;
13
13
import Image from 'next/image' ;
14
14
import { BASE_DATA_URL , type Feature } from '@/lib/constants' ;
15
15
import { FormattedAddress } from '@/lib/utils' ;
@@ -140,15 +140,42 @@ const PrecompilesTable = ({ featureData }: { featureData: Record<string, Precomp
140
140
} ;
141
141
142
142
const OpcodesTable = ( { featureData } : { featureData : Record < string , Opcodes > } ) => {
143
+ const opcodeRefs = useRef < Record < string , HTMLTableRowElement | null > > ( { } ) ;
144
+
145
+ useEffect ( ( ) => {
146
+ const hash = window . location . hash . substring ( 1 ) ;
147
+ if ( hash && opcodeRefs . current [ hash ] ) {
148
+ opcodeRefs . current [ hash ] ?. scrollIntoView ( { behavior : 'smooth' , block : 'center' } ) ;
149
+ }
150
+ } , [ ] ) ;
151
+
143
152
return (
144
153
< tbody className = { tbodyClasses } >
145
154
{ Object . keys ( knownOpcodes )
146
155
. map ( Number )
147
156
. map ( ( op : number ) => (
148
- < tr key = { op } className = { trClasses } >
149
- < td className = { td1Classes } >
150
- { knownOpcodes [ op ] }
151
- < div className = "text-secondary text-sm" > { toUppercaseHex ( op ) } </ div >
157
+ < tr
158
+ key = { op }
159
+ className = { trClasses }
160
+ ref = { ( el ) => {
161
+ opcodeRefs . current [ knownOpcodes [ op ] ] = el ;
162
+ } }
163
+ >
164
+ < td className = { classNames ( td1Classes , 'text-center' ) } >
165
+ < div className = "relative inline-block" >
166
+ < Copyable
167
+ content = {
168
+ < div >
169
+ { knownOpcodes [ op ] }
170
+ < div className = "text-secondary text-sm" > { toUppercaseHex ( op ) } </ div >
171
+ </ div >
172
+ }
173
+ Icon = { LinkIcon }
174
+ textToCopy = { `${ location . href . replace ( location . hash , '' ) } #${ knownOpcodes [ op ] } ` }
175
+ // Use negative margin to "center" since the hidden link icon makes it look off-center.
176
+ className = "ml-2 -mr-2"
177
+ />
178
+ </ div >
152
179
</ td >
153
180
{ Object . keys ( featureData ) . map ( ( chainId ) => {
154
181
const opcode = featureData [ chainId ] . find ( ( opcode ) => Number ( opcode . number ) === op ) ;
0 commit comments