1import { Controller } from "@hotwired/stimulus"; 2 3// Swaps a document row's title for a rename form in place. Success re-renders 4// the page (redirect + morph), which restores the display state on its own. 5export default class extends Controller { 6 static targets = ["display", "form", "input"]; 7 8 // The server reopens this row's form when its rename failed (422). Put the 9 // caret back where it was â the reader was mid-edit, and re-finding the field 10 // is the tax the old upload_alert path already charged them once. 11 connect() { 12 if (!this.formTarget.hidden) this.#focusInput(); 13 } 14 15 show() { 16 this.displayTarget.hidden = true; 17 this.formTarget.hidden = false; 18 this.#focusInput(); 19 } 20 21 cancel() { 22 this.inputTarget.value = this.inputTarget.defaultValue; 23 this.formTarget.hidden = true; 24 this.displayTarget.hidden = false; 25 } 26 27 // This page is live: create and destroy broadcast a refresh, so a teammate's 28 // upload can land a morph while someone here is typing. Morphing the row back 29 // to server state would close the form and discard the edit. Bound at @window 30 // because Turbo dispatches this bubbling â check the target so a nested 31 // element's event doesn't freeze the whole row. 32 // 33 // Only while open. A closed row morphs normally and keeps picking up new 34 // titles from the server, which is what keeps #cancel's defaultValue honest. 35 preserveDuringMorph(event) { 36 if (event.target === this.element && !this.formTarget.hidden) event.preventDefault(); 37 } 38 39 // Turbo snapshots the live DOM, so an open form would come back open â and 40 // holding a half-typed title â on the back button. Wired by the global 41 // turbo:before-cache hook in controllers/application.js. 42 teardown() { 43 if (!this.formTarget.hidden) this.cancel(); 44 } 45 46 #focusInput() { 47 this.inputTarget.focus(); 48 this.inputTarget.select(); 49 } 50}
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.