@@ -3,6 +3,7 @@ import Brackets from 'src/components/Brackets';
3
3
import CheckController from 'src/components/CheckController' ;
4
4
import Carets from 'src/components/Carets' ;
5
5
import { getDataType , JSONFlattenReturnType , stringToAutoType } from 'src/utils' ;
6
+ import { useClipboard } from 'src/hooks/useClipboard' ;
6
7
import './styles.less' ;
7
8
8
9
export interface NodeDataType extends JSONFlattenReturnType {
@@ -11,6 +12,16 @@ export interface NodeDataType extends JSONFlattenReturnType {
11
12
12
13
// The props here will be exposed to the user through the topmost component.
13
14
export 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
+ } ,
14
25
// Whether to display the length of (array|object).
15
26
showLength : {
16
27
type : Boolean ,
@@ -214,6 +225,16 @@ export default defineComponent({
214
225
}
215
226
} ;
216
227
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
+
217
238
return ( ) => {
218
239
const { node } = props ;
219
240
@@ -305,6 +326,10 @@ export default defineComponent({
305
326
< span class = "vjs-comment" > // { node . length } items </ span >
306
327
) }
307
328
</ span >
329
+
330
+ < span class = "vjs-tree-node-actions" >
331
+ < span onClick = { handleCopy } > copy</ span >
332
+ </ span >
308
333
</ div >
309
334
) ;
310
335
} ;
0 commit comments