1import { Controller } from '@hotwired/stimulus' 2 3export default class TurboConfirmController extends Controller { 4 5 static targets = ['title', 'body'] 6 7 connect() { 8 Turbo.setConfirmMethod((message) => this._ask(message)) 9 } 10 11 // Admin's layout has no modal controller, so this dialog is absent there and a 12 // Turbo visit into it would leave the hook awaiting a promise nothing settles. 13 disconnect() { 14 Turbo.setConfirmMethod((message) => window.confirm(message)) 15 this._settle(false) 16 } 17 18 accept() { 19 this._settle(true) 20 } 21 22 reject() { 23 this._settle(false) 24 } 25 26 _ask(message) { 27 this._settle(false) 28 29 const [title, ...rest] = message.split('\n') 30 const body = rest.join(' ').trim() 31 32 this.titleTarget.textContent = title 33 this.bodyTarget.textContent = body 34 this.bodyTarget.hidden = !body 35 36 this.dispatch('request-reveal', { prefix: 'modal', target: window, detail: { modalId: `#${this.element.id}` }}) 37 38 return new Promise((resolve) => { this._resolve = resolve }) 39 } 40 41 _settle(accepted) { 42 this._resolve?.(accepted) 43 this._resolve = null 44 } 45 46}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.