1
1
import { useEditorEngine } from '@/components/store/editor' ;
2
- import { MouseAction } from '@onlook/models/editor' ;
2
+ import { MouseAction , EditorTabValue } from '@onlook/models/editor' ;
3
3
import type { DomElement , LayerNode } from '@onlook/models/element' ;
4
+ import {
5
+ ContextMenu ,
6
+ ContextMenuContent ,
7
+ ContextMenuItem ,
8
+ ContextMenuTrigger ,
9
+ } from '@onlook/ui/context-menu' ;
4
10
import { Icons } from '@onlook/ui/icons' ;
5
11
import { Tooltip , TooltipContent , TooltipPortal , TooltipTrigger } from '@onlook/ui/tooltip' ;
6
12
import { cn } from '@onlook/ui/utils' ;
@@ -252,17 +258,36 @@ export const TreeNode = memo(
252
258
) ;
253
259
}
254
260
261
+ function viewSource ( oid : string | null ) {
262
+ if ( ! oid ) {
263
+ console . error ( 'No oid found' ) ;
264
+ return ;
265
+ }
266
+ editorEngine . code . viewCodeBlock ( oid ) ;
267
+ }
268
+
269
+ const menuItems = [
270
+ {
271
+ label : 'View Code' ,
272
+ action : ( ) => viewSource ( node . data . oid ) ,
273
+ icon : < Icons . ExternalLink className = "mr-2 h-4 w-4" /> ,
274
+ disabled : ! node . data . oid || isWindow ,
275
+ } ,
276
+ ] ;
277
+
255
278
return (
256
- < Tooltip >
257
- < TooltipTrigger asChild >
258
- < div ref = { nodeRef } >
259
- < div
260
- ref = { dragHandle }
261
- style = { style }
262
- onMouseDown = { ( e ) => handleSelectNode ( e ) }
263
- onMouseOver = { ( e ) => handleHoverNode ( e ) }
264
- className = { nodeClassName }
265
- >
279
+ < ContextMenu >
280
+ < ContextMenuTrigger asChild >
281
+ < Tooltip >
282
+ < TooltipTrigger asChild >
283
+ < div ref = { nodeRef } >
284
+ < div
285
+ ref = { dragHandle }
286
+ style = { style }
287
+ onMouseDown = { ( e ) => handleSelectNode ( e ) }
288
+ onMouseOver = { ( e ) => handleHoverNode ( e ) }
289
+ className = { nodeClassName }
290
+ >
266
291
< span className = "w-4 h-4 flex-none relative" >
267
292
{ ! node . isLeaf && (
268
293
< div
@@ -358,9 +383,9 @@ export const TreeNode = memo(
358
383
onClick = { toggleVisibility }
359
384
/>
360
385
) }
361
- </ div >
362
- </ div >
363
- </ TooltipTrigger >
386
+ </ div >
387
+ </ div >
388
+ </ TooltipTrigger >
364
389
{ node . data . textContent !== '' && (
365
390
< TooltipPortal container = { document . getElementById ( 'style-panel' ) } >
366
391
< TooltipContent
@@ -374,7 +399,24 @@ export const TreeNode = memo(
374
399
</ TooltipPortal >
375
400
) }
376
401
</ Tooltip >
377
- ) ;
402
+ </ ContextMenuTrigger >
403
+ < ContextMenuContent >
404
+ { menuItems . map ( ( item ) => (
405
+ < ContextMenuItem
406
+ key = { item . label }
407
+ onClick = { item . action }
408
+ className = "cursor-pointer"
409
+ disabled = { item . disabled }
410
+ >
411
+ < span className = { cn ( 'flex w-full items-center gap-1' ) } >
412
+ { item . icon }
413
+ { item . label }
414
+ </ span >
415
+ </ ContextMenuItem >
416
+ ) ) }
417
+ </ ContextMenuContent >
418
+ </ ContextMenu >
419
+ ) ;
378
420
} ,
379
421
) ,
380
422
) ;
0 commit comments