Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const perTabInit = (tab: Tab, tabButton: HTMLElement, doListen = true) => {
tab.state = new TabState()
const newTabId = uuid()
tab.setAttribute('data-tab-id', newTabId)
tabButton.setAttribute('data-tab-id', newTabId)
tabButton.onclick = () => switchTab(newTabId)
setTimeout(async () => {
getReplImpl(tab)
eventBus.emit('/tab/new', tab)
})
if (doListen) {
listen(getCurrentPrompt(tab))
}
// keep repl prompt focused, if possible
const grabFocus = (checkPath: boolean) => (evt: MouseEvent) => {
const target = evt.target
if (isElement(target)) {
setTimeout(() => {
const prompt = getCurrentPrompt(tab)
if (
prompt &&
getSelectionText().length === 0 &&
(target.classList.contains('repl-inner') ||
target.classList.contains('repl-output') ||
target.classList.contains('kui--tab-navigatable') ||
(checkPath && evt['path'] && evt['path'].find(_ => isElement(_) && /header/i.test(_.tagName))))
) {
setStatus(currentlyProcessingBlock, Status.replActive)
}
// this must occur after the REPL.qexec('clear'), otherwise we may select
// the wrong repl-result
empty(newTab.querySelector('.repl-result'))
clearSelection(newTab)
perTabInit(newTab, newTabButton)
newTabButton.scrollIntoView()
// make the new tab visible at the very end of the above init work!
currentVisibleTab.classList.remove('visible')
currentVisibleTab.parentNode.appendChild(newTab)
getCurrentPrompt(newTab).focus()
getTabButtonLabel(newTab).innerText = !isUsingCommandName() ? strings('Tab') : strings('New Tab')
return true
}
cancelButton.classList.add('bx--btn--secondary')
cancelButton.classList.add('button-custon')
cancelButton.setAttribute('type', 'button')
cancelButton.innerText = strings('cancel')
cancelButton.onclick = cancel
continueButton.classList.add('bx--btn')
continueButton.classList.add('bx--btn--danger')
continueButton.classList.add('button-custon')
continueButton.setAttribute('type', 'button')
continueButton.innerText = strings('yesIAmSure')
continueButton.onclick = exec
// temporarily disable the repl
if (getCurrentPrompt(tab)) {
getCurrentPrompt(tab).readOnly = true
}
// to capture the Escape key event
const hiddenInput = document.createElement('input')
hiddenInput.classList.add('hidden')
hiddenInput.classList.add('grab-focus')
modal.appendChild(hiddenInput)
hiddenInput.focus()
modal.addEventListener(
'keyup',
(evt: KeyboardEvent) => {
if (evt.keyCode === KeyCodes.ESCAPE) {
evt.preventDefault()
cancel()
}
setTimeout(() => {
page.removeChild(snapDom)
getCurrentPrompt(tab).readOnly = false
getCurrentPrompt(tab).focus()
}, 1000) // match go-away-able transition-duration; see ui.css
}
tab['_kui_session'] = new Promise(async (resolve, reject) => {
try {
const block = getCurrentBlock(tab)
const prompt = getCurrentPrompt(tab)
prompt.readOnly = true
let placeholderChanged = false
const sessionInitialization = pollUntilOnline(tab, block)
// change the placeholder if sessionInitialization is slow
const placeholderAsync = setTimeout(() => {
prompt.placeholder = strings('Please wait while we connect to your cloud')
setStatus(block, Status.processing)
placeholderChanged = true
}, theme.millisBeforeProxyConnectionWarning || 250)
await sessionInitialization
clearTimeout(placeholderAsync)
prompt.readOnly = false
cancelButton.classList.add('bx--btn')
cancelButton.classList.add('bx--btn--secondary')
cancelButton.classList.add('button-custon')
cancelButton.setAttribute('type', 'button')
cancelButton.innerText = strings('cancel')
cancelButton.onclick = cancel
continueButton.classList.add('bx--btn')
continueButton.classList.add('bx--btn--danger')
continueButton.classList.add('button-custon')
continueButton.setAttribute('type', 'button')
continueButton.innerText = strings('yesIAmSure')
continueButton.onclick = exec
// temporarily disable the repl
if (getCurrentPrompt(tab)) {
getCurrentPrompt(tab).readOnly = true
}
// to capture the Escape key event
const hiddenInput = document.createElement('input')
hiddenInput.classList.add('hidden')
hiddenInput.classList.add('grab-focus')
modal.appendChild(hiddenInput)
hiddenInput.focus()
modal.addEventListener(
'keyup',
(evt: KeyboardEvent) => {
if (evt.keyCode === KeyCodes.ESCAPE) {
evt.preventDefault()
cancel()
clearHighlights()
// $(window).unbind("resize", resizeHandler);
// allow for the close transition to do its magic
if (delay === 0) {
// $(pane).remove();
resolve(true)
} else {
setTimeout(() => {
// $(pane).remove();
resolve(true)
}, delay)
}
// make sure the repl has focus when we're done
getCurrentPrompt().focus()
})
setTimeout(() => {
const prompt = getCurrentPrompt(tab)
if (
prompt &&
getSelectionText().length === 0 &&
(target.classList.contains('repl-inner') ||
target.classList.contains('repl-output') ||
target.classList.contains('kui--tab-navigatable') ||
(checkPath && evt['path'] && evt['path'].find(_ => isElement(_) && /header/i.test(_.tagName))))
) {
if (target.classList.contains('repl-inner') || isInViewport(prompt)) {
prompt.focus()
}
}
}, 0)
}
;(document.querySelector('.main > .left-tab-stripe') as HTMLElement).onclick = () => {
const prompt = getCurrentPrompt()
if (prompt) {
prompt.focus()
}
}
}