Add cmd-k to delete current line
All checks were successful
Build / build (push) Successful in 2m31s
All checks were successful
Build / build (push) Successful in 2m31s
This commit is contained in:
parent
3e8d101eec
commit
d64779f660
10 changed files with 166 additions and 0 deletions
42
frontend/src/controllers/prompt_controller.js
Normal file
42
frontend/src/controllers/prompt_controller.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export class PromptController extends Controller {
|
||||
static targets = [
|
||||
"label",
|
||||
"input",
|
||||
];
|
||||
|
||||
connect() {
|
||||
this._callback = null;
|
||||
|
||||
window.runtime.EventsOn("prompt-request", (data) => {
|
||||
this.prompt(data.label, (res) => {
|
||||
window.runtime.EventsEmit("prompt-response", res);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
prompt(label, callback) {
|
||||
this._callback = callback;
|
||||
this.labelTarget.textContent = label;
|
||||
this.inputTarget.value = "";
|
||||
this.element.showModal();
|
||||
this.inputTarget.focus();
|
||||
}
|
||||
|
||||
submit(ev) {
|
||||
ev.preventDefault();
|
||||
let value = this.inputTarget.value;
|
||||
this.element.close();
|
||||
if (this._callback) {
|
||||
this._callback(value);
|
||||
this._callback = null;
|
||||
}
|
||||
}
|
||||
|
||||
dismiss(ev) {
|
||||
ev.preventDefault();
|
||||
this._callback = null;
|
||||
this.element.close();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue