Fix Beat Prompt input focus
This commit is contained in:
@@ -286,6 +286,18 @@ function setDirectiveValue(text, canonicalName, directiveNames, value) {
|
||||
return cleaned ? `${directiveLine}\n${cleaned}` : directiveLine;
|
||||
}
|
||||
|
||||
function isInteractiveTarget(target) {
|
||||
return !!target?.closest?.("textarea, input, select, button, label");
|
||||
}
|
||||
|
||||
function stopCanvasEvent(event) {
|
||||
if (isInteractiveTarget(event.target)) event.stopPropagation();
|
||||
}
|
||||
|
||||
function stopCanvasKeyboard(event) {
|
||||
if (isInteractiveTarget(event.target)) event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
function renderUI(node) {
|
||||
const ui = node._dh3bpUI;
|
||||
if (!ui) return;
|
||||
@@ -328,7 +340,7 @@ function renderUI(node) {
|
||||
writeState(node, next);
|
||||
updateTextareaHeight(textarea);
|
||||
});
|
||||
textarea.addEventListener("keydown", (event) => event.stopImmediatePropagation());
|
||||
textarea.addEventListener("keydown", stopCanvasKeyboard);
|
||||
|
||||
const applyTextUpdate = (nextText) => {
|
||||
const next = readState(node);
|
||||
@@ -492,6 +504,11 @@ function setupNode(node) {
|
||||
list.className = "dh3bp-list";
|
||||
|
||||
root.append(toolbar, list);
|
||||
root.addEventListener("pointerdown", stopCanvasEvent);
|
||||
root.addEventListener("mousedown", stopCanvasEvent);
|
||||
root.addEventListener("click", stopCanvasEvent);
|
||||
root.addEventListener("dblclick", stopCanvasEvent);
|
||||
root.addEventListener("keydown", stopCanvasKeyboard, true);
|
||||
|
||||
node._dh3bpUI = { root, list };
|
||||
const widget = node.addDOMWidget("dumas_h3_beat_prompt", "custom", root, {
|
||||
|
||||
Reference in New Issue
Block a user