{"version":3,"file":"focusTextareaFromPromptWrapper.mjs","names":[],"sources":["../../../../src/ai/prompt/focusTextareaFromPromptWrapper.ts"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport type { MouseEventHandler } from 'react';\n\nconst MAX_POINTER_MOVE_PX = 3;\nconst NON_FOCUSABLE_TARGET_SELECTOR = [\n  'textarea',\n  'button',\n  'a',\n  'input',\n  'select',\n  '[role=\"button\"]',\n  '.ndl-ai-prompt-context-tag',\n  '.ndl-ai-file-tag',\n  '.ndl-ai-image-tag',\n].join(',');\n\n/**\n * Focuses the prompt textarea when users click the non-interactive wrapper.\n *\n * This keeps keyboard input in sync with the visible focused state.\n */\nexport const focusTextareaFromPromptWrapper: MouseEventHandler<\n  HTMLDivElement\n> = (event) => {\n  if (event.button !== 0) {\n    return;\n  }\n\n  const container = event.currentTarget;\n  const target = event.target instanceof HTMLElement ? event.target : null;\n  const textarea = container.querySelector('textarea');\n\n  if (textarea === null) {\n    return;\n  }\n\n  // Do not override focus/behavior when users click interactive controls.\n  if (target?.closest(NON_FOCUSABLE_TARGET_SELECTOR)) {\n    return;\n  }\n\n  let didMove = false;\n  const startX = event.clientX;\n  const startY = event.clientY;\n\n  const cleanup = () => {\n    window.removeEventListener('mousemove', handleMouseMove);\n    window.removeEventListener('mouseup', handleMouseUp);\n  };\n\n  const handleMouseMove = (moveEvent: MouseEvent) => {\n    if (\n      Math.abs(moveEvent.clientX - startX) > MAX_POINTER_MOVE_PX ||\n      Math.abs(moveEvent.clientY - startY) > MAX_POINTER_MOVE_PX\n    ) {\n      didMove = true;\n    }\n  };\n\n  const handleMouseUp = (upEvent: MouseEvent) => {\n    cleanup();\n\n    if (didMove) {\n      return;\n    }\n\n    const upTarget =\n      upEvent.target instanceof HTMLElement ? upEvent.target : null;\n\n    if (\n      upTarget === null ||\n      !container.contains(upTarget) ||\n      upTarget.closest(NON_FOCUSABLE_TARGET_SELECTOR)\n    ) {\n      return;\n    }\n\n    textarea.focus();\n  };\n\n  window.addEventListener('mousemove', handleMouseMove);\n  window.addEventListener('mouseup', handleMouseUp);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,sBAAsB;AAC5B,MAAM,gCAAgC;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,GAAG;;;;;;AAOV,MAAa,kCAER,UAAU;CACb,IAAI,MAAM,WAAW,GACnB;CAGF,MAAM,YAAY,MAAM;CACxB,MAAM,SAAS,MAAM,kBAAkB,cAAc,MAAM,SAAS;CACpE,MAAM,WAAW,UAAU,cAAc,UAAU;CAEnD,IAAI,aAAa,MACf;CAIF,IAAA,WAAA,QAAA,WAAA,KAAA,IAAA,KAAA,IAAI,OAAQ,QAAQ,6BAA6B,GAC/C;CAGF,IAAI,UAAU;CACd,MAAM,SAAS,MAAM;CACrB,MAAM,SAAS,MAAM;CAErB,MAAM,gBAAgB;EACpB,OAAO,oBAAoB,aAAa,eAAe;EACvD,OAAO,oBAAoB,WAAW,aAAa;CACrD;CAEA,MAAM,mBAAmB,cAA0B;EACjD,IACE,KAAK,IAAI,UAAU,UAAU,MAAM,IAAI,uBACvC,KAAK,IAAI,UAAU,UAAU,MAAM,IAAI,qBAEvC,UAAU;CAEd;CAEA,MAAM,iBAAiB,YAAwB;EAC7C,QAAQ;EAER,IAAI,SACF;EAGF,MAAM,WACJ,QAAQ,kBAAkB,cAAc,QAAQ,SAAS;EAE3D,IACE,aAAa,QACb,CAAC,UAAU,SAAS,QAAQ,KAC5B,SAAS,QAAQ,6BAA6B,GAE9C;EAGF,SAAS,MAAM;CACjB;CAEA,OAAO,iBAAiB,aAAa,eAAe;CACpD,OAAO,iBAAiB,WAAW,aAAa;AAClD"}