@@ -21,6 +21,7 @@ const appGrid = document.querySelector('.app-grid')
2121const githubAiControls = document . getElementById ( 'github-ai-controls' )
2222const githubTokenInput = document . getElementById ( 'github-token-input' )
2323const githubTokenInfo = document . getElementById ( 'github-token-info' )
24+ const githubTokenInfoPanel = document . getElementById ( 'github-token-info-panel' )
2425const githubTokenAdd = document . getElementById ( 'github-token-add' )
2526const githubTokenDelete = document . getElementById ( 'github-token-delete' )
2627const githubRepoWrap = document . getElementById ( 'github-repo-wrap' )
@@ -110,6 +111,7 @@ const compactViewportMediaQuery = window.matchMedia('(max-width: 900px)')
110111const stackedRailMediaQuery = window . matchMedia ( '(max-width: 1090px)' )
111112let stackedRailViewControlsOpen = false
112113let compactAiControlsOpen = false
114+ let githubTokenInfoOpen = false
113115
114116const isStackedRailViewport = ( ) => stackedRailMediaQuery . matches
115117
@@ -139,13 +141,30 @@ const setStackedRailViewControlsOpen = isOpen => {
139141 viewControlsDrawer . setAttribute ( 'hidden' , '' )
140142}
141143
144+ const setGitHubTokenInfoOpen = isOpen => {
145+ if ( ! ( githubTokenInfo instanceof HTMLButtonElement ) || ! githubTokenInfoPanel ) {
146+ return
147+ }
148+
149+ githubTokenInfoOpen = Boolean ( isOpen )
150+ githubTokenInfo . setAttribute ( 'aria-expanded' , githubTokenInfoOpen ? 'true' : 'false' )
151+
152+ if ( githubTokenInfoOpen ) {
153+ githubTokenInfoPanel . removeAttribute ( 'hidden' )
154+ return
155+ }
156+
157+ githubTokenInfoPanel . setAttribute ( 'hidden' , '' )
158+ }
159+
142160const setCompactAiControlsOpen = isOpen => {
143161 if ( ! ( aiControlsToggle instanceof HTMLButtonElement ) || ! githubAiControls ) {
144162 return
145163 }
146164
147165 if ( ! aiAssistantFeatureEnabled ) {
148166 compactAiControlsOpen = false
167+ setGitHubTokenInfoOpen ( false )
149168 aiControlsToggle . setAttribute ( 'hidden' , '' )
150169 aiControlsToggle . setAttribute ( 'aria-expanded' , 'false' )
151170 githubAiControls . removeAttribute ( 'data-compact-open' )
@@ -157,6 +176,7 @@ const setCompactAiControlsOpen = isOpen => {
157176
158177 if ( ! isCompactViewport ( ) ) {
159178 compactAiControlsOpen = false
179+ setGitHubTokenInfoOpen ( false )
160180 aiControlsToggle . setAttribute ( 'aria-expanded' , 'false' )
161181 githubAiControls . removeAttribute ( 'data-compact-open' )
162182 githubAiControls . removeAttribute ( 'hidden' )
@@ -166,6 +186,10 @@ const setCompactAiControlsOpen = isOpen => {
166186 compactAiControlsOpen = Boolean ( isOpen )
167187 aiControlsToggle . setAttribute ( 'aria-expanded' , compactAiControlsOpen ? 'true' : 'false' )
168188 githubAiControls . dataset . compactOpen = compactAiControlsOpen ? 'true' : 'false'
189+
190+ if ( ! compactAiControlsOpen ) {
191+ setGitHubTokenInfoOpen ( false )
192+ }
169193}
170194
171195const getCurrentLayout = ( ) => {
@@ -508,6 +532,15 @@ const byotControls = createGitHubByotControls({
508532 githubAiContextState . selectedRepository = repository
509533 chatDrawerController . setSelectedRepository ( repository )
510534 } ,
535+ onTokenDeleteRequest : onConfirm => {
536+ confirmAction ( {
537+ title : 'Remove saved GitHub token?' ,
538+ copy : 'This action removes the token from browser storage. You can add another token at any time.' ,
539+ fallbackConfirmText :
540+ 'Remove saved GitHub token? This action removes the token from browser storage.' ,
541+ onConfirm,
542+ } )
543+ } ,
511544 onTokenChange : token => {
512545 githubAiContextState . token = token
513546 syncAiChatTokenVisibility ( token )
@@ -943,17 +976,13 @@ const clearStylesSource = () => {
943976 maybeRender ( )
944977}
945978
946- const confirmClearSource = ( { label , onConfirm } ) => {
979+ const confirmAction = ( { title , copy , fallbackConfirmText , onConfirm } ) => {
947980 const supportsModalDialog =
948981 clearConfirmDialog instanceof HTMLDialogElement &&
949982 typeof clearConfirmDialog . showModal === 'function'
950983
951984 if ( ! supportsModalDialog ) {
952- if (
953- window . confirm (
954- `Clear ${ label . toLowerCase ( ) } source? This action will remove all text from the editor.` ,
955- )
956- ) {
985+ if ( window . confirm ( fallbackConfirmText ) ) {
957986 onConfirm ( )
958987 }
959988 return
@@ -964,18 +993,26 @@ const confirmClearSource = ({ label, onConfirm }) => {
964993 }
965994
966995 if ( clearConfirmTitle ) {
967- clearConfirmTitle . textContent = `Clear ${ label } source?`
996+ clearConfirmTitle . textContent = title
968997 }
969998
970999 if ( clearConfirmCopy ) {
971- clearConfirmCopy . textContent =
972- 'This action will remove all text from the editor. This cannot be undone.'
1000+ clearConfirmCopy . textContent = copy
9731001 }
9741002
9751003 pendingClearAction = onConfirm
9761004 clearConfirmDialog . showModal ( )
9771005}
9781006
1007+ const confirmClearSource = ( { label, onConfirm } ) => {
1008+ confirmAction ( {
1009+ title : `Clear ${ label } source?` ,
1010+ copy : 'This action will remove all text from the editor. This cannot be undone.' ,
1011+ fallbackConfirmText : `Clear ${ label . toLowerCase ( ) } source? This action will remove all text from the editor.` ,
1012+ onConfirm,
1013+ } )
1014+ }
1015+
9791016const copyTextToClipboard = async text => {
9801017 if ( ! clipboardSupported ) {
9811018 throw new Error ( 'Clipboard API is not available in this browser context.' )
@@ -1186,6 +1223,13 @@ if (aiControlsToggle instanceof HTMLButtonElement) {
11861223 } )
11871224}
11881225
1226+ if ( githubTokenInfo instanceof HTMLButtonElement && githubTokenInfoPanel ) {
1227+ githubTokenInfo . addEventListener ( 'click' , event => {
1228+ event . preventDefault ( )
1229+ setGitHubTokenInfoOpen ( ! githubTokenInfoOpen )
1230+ } )
1231+ }
1232+
11891233document . addEventListener ( 'click' , event => {
11901234 const clickTarget = event . target
11911235 if ( ! ( clickTarget instanceof Node ) ) {
@@ -1209,6 +1253,15 @@ document.addEventListener('click', event => {
12091253 setCompactAiControlsOpen ( false )
12101254 }
12111255 }
1256+
1257+ if ( githubTokenInfoOpen ) {
1258+ if (
1259+ ! githubTokenInfo ?. contains ( clickTarget ) &&
1260+ ! githubTokenInfoPanel ?. contains ( clickTarget )
1261+ ) {
1262+ setGitHubTokenInfoOpen ( false )
1263+ }
1264+ }
12121265} )
12131266
12141267document . addEventListener ( 'keydown' , event => {
@@ -1218,6 +1271,7 @@ document.addEventListener('keydown', event => {
12181271
12191272 setStackedRailViewControlsOpen ( false )
12201273 setCompactAiControlsOpen ( false )
1274+ setGitHubTokenInfoOpen ( false )
12211275} )
12221276
12231277for ( const button of editorToolsButtons ) {
@@ -1277,6 +1331,7 @@ applyEditorToolsVisibility()
12771331applyPanelCollapseState ( )
12781332setStackedRailViewControlsOpen ( false )
12791333setCompactAiControlsOpen ( false )
1334+ setGitHubTokenInfoOpen ( false )
12801335syncAiChatTokenVisibility ( githubAiContextState . token )
12811336
12821337updateRenderButtonVisibility ( )
0 commit comments