1import {Controller} from '@hotwired/stimulus' 2 3export default class extends Controller { 4 static targets = ['input'] 5 static values = {url: String, param: {type: String, default: 'query'}, debounce: {type: Number, default: 250}} 6 7 disconnect() { 8 clearTimeout(this.timer) 9 } 10 11 search() { 12 clearTimeout(this.timer) 13 this.timer = setTimeout(() => this.fetchResults(), this.debounceValue) 14 } 15 16 fetchResults() { 17 const url = new URL(this.urlValue, window.location.origin) 18 url.searchParams.set(this.paramValue, this.inputTarget.value.trim()) 19 fetch(url, {headers: {Accept: 'text/vnd.turbo-stream.html'}}) 20 .then(response => response.text()) 21 .then(html => Turbo.renderStreamMessage(html)) 22 } 23}
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.