@@ -3,6 +3,7 @@ import Brackets from 'src/components/Brackets';
33import CheckController from 'src/components/CheckController' ;
44import Carets from 'src/components/Carets' ;
55import { getDataType , JSONFlattenReturnType , stringToAutoType } from 'src/utils' ;
6+ import { useClipboard } from 'src/hooks/useClipboard' ;
67import './styles.less' ;
78
89export interface NodeDataType extends JSONFlattenReturnType {
@@ -11,6 +12,16 @@ export interface NodeDataType extends JSONFlattenReturnType {
1112
1213// The props here will be exposed to the user through the topmost component.
1314export const treeNodePropsPass = {
15+ // JSONLike data.
16+ data : {
17+ type : [ String , Number , Boolean , Array , Object ] as PropType < JSONDataType > ,
18+ default : null ,
19+ } ,
20+ // Data root path.
21+ rootPath : {
22+ type : String ,
23+ default : 'root' ,
24+ } ,
1425 // Whether to display the length of (array|object).
1526 showLength : {
1627 type : Boolean ,
@@ -214,6 +225,16 @@ export default defineComponent({
214225 }
215226 } ;
216227
228+ const { copy } = useClipboard ( ) ;
229+
230+ const handleCopy = ( ) => {
231+ const { key, path } = props . node ;
232+ const rootPath = props . rootPath ;
233+ const content = new Function ( 'data' , `return data${ path . slice ( rootPath . length ) } ` ) ( props . data ) ;
234+ const copiedData = JSON . stringify ( key ? { [ key ] : content } : content , null , 2 ) ;
235+ copy ( copiedData ) ;
236+ }
237+
217238 return ( ) => {
218239 const { node } = props ;
219240
@@ -305,6 +326,10 @@ export default defineComponent({
305326 < span class = "vjs-comment" > // { node . length } items </ span >
306327 ) }
307328 </ span >
329+
330+ < span class = "vjs-tree-node-actions" >
331+ < span onClick = { handleCopy } > copy</ span >
332+ </ span >
308333 </ div >
309334 ) ;
310335 } ;
0 commit comments