22// SPDX-License-Identifier: Apache-2.0
33
44import { getTabBadgeAtom } from "@/app/store/badge" ;
5- import { getOrefMetaKeyAtom , globalStore , recordTEvent , refocusNode } from "@/app/store/global" ;
5+ import { refocusNode } from "@/app/store/global" ;
66import { TabRpcClient } from "@/app/store/wshrpcutil" ;
77import { WaveEnv , WaveEnvSubset , useWaveEnv } from "@/app/waveenv/waveenv" ;
88import { Button } from "@/element/button" ;
@@ -14,8 +14,9 @@ import { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useRef,
1414import { makeORef } from "../store/wos" ;
1515import { TabBadges } from "./tabbadges" ;
1616import "./tab.scss" ;
17+ import { buildTabContextMenu } from "./tabcontextmenu" ;
1718
18- type TabEnv = WaveEnvSubset < {
19+ export type TabEnv = WaveEnvSubset < {
1920 rpc : {
2021 ActivityCommand : WaveEnv [ "rpc" ] [ "ActivityCommand" ] ;
2122 SetMetaCommand : WaveEnv [ "rpc" ] [ "SetMetaCommand" ] ;
@@ -216,88 +217,6 @@ const TabV = forwardRef<HTMLDivElement, TabVProps>((props, ref) => {
216217
217218TabV . displayName = "TabV" ;
218219
219- const FlagColors : { label : string ; value : string } [ ] = [
220- { label : "Green" , value : "#58C142" } ,
221- { label : "Teal" , value : "#00FFDB" } ,
222- { label : "Blue" , value : "#429DFF" } ,
223- { label : "Purple" , value : "#BF55EC" } ,
224- { label : "Red" , value : "#FF453A" } ,
225- { label : "Orange" , value : "#FF9500" } ,
226- { label : "Yellow" , value : "#FFE900" } ,
227- ] ;
228-
229- function buildTabContextMenu (
230- id : string ,
231- renameRef : React . RefObject < ( ( ) => void ) | null > ,
232- onClose : ( event : React . MouseEvent < HTMLButtonElement , MouseEvent > | null ) => void ,
233- env : TabEnv
234- ) : ContextMenuItem [ ] {
235- const menu : ContextMenuItem [ ] = [ ] ;
236- menu . push (
237- { label : "Rename Tab" , click : ( ) => renameRef . current ?.( ) } ,
238- {
239- label : "Copy TabId" ,
240- click : ( ) => fireAndForget ( ( ) => navigator . clipboard . writeText ( id ) ) ,
241- } ,
242- { type : "separator" }
243- ) ;
244- const tabORef = makeORef ( "tab" , id ) ;
245- const currentFlagColor = globalStore . get ( getOrefMetaKeyAtom ( tabORef , "tab:flagcolor" ) ) ?? null ;
246- const flagSubmenu : ContextMenuItem [ ] = [
247- {
248- label : "None" ,
249- type : "checkbox" ,
250- checked : currentFlagColor == null ,
251- click : ( ) =>
252- fireAndForget ( ( ) =>
253- env . rpc . SetMetaCommand ( TabRpcClient , { oref : tabORef , meta : { "tab:flagcolor" : null } } )
254- ) ,
255- } ,
256- ...FlagColors . map ( ( fc ) => ( {
257- label : fc . label ,
258- type : "checkbox" as const ,
259- checked : currentFlagColor === fc . value ,
260- click : ( ) =>
261- fireAndForget ( ( ) =>
262- env . rpc . SetMetaCommand ( TabRpcClient , { oref : tabORef , meta : { "tab:flagcolor" : fc . value } } )
263- ) ,
264- } ) ) ,
265- ] ;
266- menu . push ( { label : "Flag Tab" , type : "submenu" , submenu : flagSubmenu } , { type : "separator" } ) ;
267- const fullConfig = globalStore . get ( env . atoms . fullConfigAtom ) ;
268- const bgPresets : string [ ] = [ ] ;
269- for ( const key in fullConfig ?. presets ?? { } ) {
270- if ( key . startsWith ( "bg@" ) && fullConfig . presets [ key ] != null ) {
271- bgPresets . push ( key ) ;
272- }
273- }
274- bgPresets . sort ( ( a , b ) => {
275- const aOrder = fullConfig . presets [ a ] [ "display:order" ] ?? 0 ;
276- const bOrder = fullConfig . presets [ b ] [ "display:order" ] ?? 0 ;
277- return aOrder - bOrder ;
278- } ) ;
279- if ( bgPresets . length > 0 ) {
280- const submenu : ContextMenuItem [ ] = [ ] ;
281- const oref = makeORef ( "tab" , id ) ;
282- for ( const presetName of bgPresets ) {
283- // preset cannot be null (filtered above)
284- const preset = fullConfig . presets [ presetName ] ;
285- submenu . push ( {
286- label : preset [ "display:name" ] ?? presetName ,
287- click : ( ) =>
288- fireAndForget ( async ( ) => {
289- await env . rpc . SetMetaCommand ( TabRpcClient , { oref, meta : preset } ) ;
290- env . rpc . ActivityCommand ( TabRpcClient , { settabtheme : 1 } , { noresponse : true } ) ;
291- recordTEvent ( "action:settabtheme" ) ;
292- } ) ,
293- } ) ;
294- }
295- menu . push ( { label : "Backgrounds" , type : "submenu" , submenu } , { type : "separator" } ) ;
296- }
297- menu . push ( { label : "Close Tab" , click : ( ) => onClose ( null ) } ) ;
298- return menu ;
299- }
300-
301220interface TabProps {
302221 id : string ;
303222 active : boolean ;
0 commit comments