{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/data-grid/data-grid-nav/index.tsx"],"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 */\nimport type React from 'react';\nimport { useCallback, useMemo, useRef, useState } from 'react';\n\nimport { type Config, DataGridNav } from './data-grid-nav';\n\nexport function useTableNav(options?: Config) {\n  // Store the actual class instance in a ref so we only create it once\n  const instanceRef = useRef<DataGridNav | null>(null);\n  if (instanceRef.current === null) {\n    instanceRef.current = new DataGridNav(options);\n  }\n\n  // A piece of state to force a re-render when you want to react to instance changes\n  const [, setVersion] = useState(0);\n  const forceUpdate = useCallback(\n    () => setVersion((version) => version + 1),\n    [],\n  );\n\n  // Wrap the instance in a proxy that intercepts reads/writes\n  const proxiedInstance = useMemo(() => {\n    const handler: ProxyHandler<DataGridNav> = {\n      get(target, prop, receiver) {\n        const value = Reflect.get(target, prop, receiver);\n\n        // If it's a function (a class method), we can intercept calls:\n        if (typeof value === 'function') {\n          // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n          return (...args: any[]) => {\n            // Call the original method\n            const result = value.apply(target, args);\n\n            // Example: force re-render if the method is known to change internal state\n            // or if you want to force re-render after *every* method call, remove the condition\n            if (['enable', 'disable'].includes(String(prop))) {\n              forceUpdate();\n            }\n            return result;\n          };\n        }\n\n        // Otherwise, it's a property. Just return it.\n        return value;\n      },\n\n      // Trap for property assignments, so React can re-render on changes\n      set(target, prop, newValue, receiver) {\n        // eslint-disable-next-line @typescript-eslint/naming-convention\n        const result = Reflect.set(target, prop, newValue, receiver);\n        // Force re-render after setting *any* property\n        forceUpdate();\n        return result;\n      },\n    };\n\n    return new Proxy(instanceRef.current as DataGridNav, handler);\n    // We only want to create a new Proxy if the instanceRef or forceUpdate changes\n  }, [forceUpdate]);\n\n  return {\n    listeners: {\n      onKeyDown: (event: React.KeyboardEvent) =>\n        proxiedInstance.tableKeyDown(event.nativeEvent),\n      onKeyUp: () => proxiedInstance.tableKeyUp(),\n    },\n    tableNav: proxiedInstance,\n  };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,YAAY,SAAkB;CAE5C,MAAM,cAAc,OAA2B,IAAI;CACnD,IAAI,YAAY,YAAY,MAC1B,YAAY,UAAU,IAAI,YAAY,OAAO;CAI/C,MAAM,GAAG,cAAc,SAAS,CAAC;CACjC,MAAM,cAAc,kBACZ,YAAY,YAAY,UAAU,CAAC,GACzC,CAAC,CACH;CAGA,MAAM,kBAAkB,cAAc;EAmCpC,OAAO,IAAI,MAAM,YAAY,SAAwB;GAjCnD,IAAI,QAAQ,MAAM,UAAU;IAC1B,MAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,QAAQ;IAGhD,IAAI,OAAO,UAAU,YAEnB,QAAQ,GAAG,SAAgB;KAEzB,MAAM,SAAS,MAAM,MAAM,QAAQ,IAAI;KAIvC,IAAI,CAAC,UAAU,SAAS,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,GAC7C,YAAY;KAEd,OAAO;IACT;IAIF,OAAO;GACT;GAGA,IAAI,QAAQ,MAAM,UAAU,UAAU;IAEpC,MAAM,SAAS,QAAQ,IAAI,QAAQ,MAAM,UAAU,QAAQ;IAE3D,YAAY;IACZ,OAAO;GACT;EAGyD,CAAC;CAE9D,GAAG,CAAC,WAAW,CAAC;CAEhB,OAAO;EACL,WAAW;GACT,YAAY,UACV,gBAAgB,aAAa,MAAM,WAAW;GAChD,eAAe,gBAAgB,WAAW;EAC5C;EACA,UAAU;CACZ;AACF"}