{"version":3,"file":"use-combobox-popover.mjs","names":["sizeMiddleware"],"sources":["../../../src/combobox/use-combobox-popover.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 */\nimport {\n  autoUpdate,\n  type Boundary,\n  flip,\n  offset,\n  shift,\n  size as sizeMiddleware,\n  useClick,\n  useDismiss,\n  useFloating,\n  useInteractions,\n} from '@floating-ui/react';\n\nimport { useIsInsideDialog } from '../dialog/dialog-context';\n\ntype UseComboboxPopoverOptions = {\n  isOpen: boolean;\n  onOpenChange: (isOpen: boolean) => void;\n  isDisabled: boolean;\n  isPortaled?: boolean;\n  floatingStrategy?: 'absolute' | 'fixed';\n};\n\n/**\n * Anchors the combobox panel to the control. Deliberately does not use\n * `useRole`, since the ARIA lives on the trigger button rather than on the\n * reference element, and the composition differs between the searchable and\n * select-only patterns.\n */\nexport function useComboboxPopover({\n  isOpen,\n  onOpenChange,\n  isDisabled,\n  isPortaled: isPortaledProp,\n  floatingStrategy,\n}: UseComboboxPopoverOptions) {\n  const isInsideDialog = useIsInsideDialog();\n  const isPortaled = isPortaledProp ?? !isInsideDialog;\n  // Inside a Dialog the panel is fixed and not portaled. A transformed\n  // ancestor can make Floating UI under-measure available space, so use the\n  // viewport as the boundary instead.\n  const floatingBoundary: Boundary = isInsideDialog ? [] : 'clippingAncestors';\n\n  const { refs, floatingStyles, context } = useFloating({\n    middleware: [\n      offset(4),\n      flip({ fallbackPlacements: ['top-start'], padding: 5 }),\n      shift({ boundary: floatingBoundary, padding: 5 }),\n      sizeMiddleware({\n        apply({ availableHeight, elements, rects }) {\n          // The reference width is a floor the stylesheet combines with its own,\n          // so a narrow trigger still gets a readable panel.\n          elements.floating.style.setProperty(\n            '--ndl-combobox-reference-width',\n            `${rects.reference.width}px`,\n          );\n          Object.assign(elements.floating.style, {\n            maxHeight: `${availableHeight}px`,\n          });\n        },\n        boundary: floatingBoundary,\n        padding: 5,\n      }),\n    ],\n    onOpenChange: (open) => {\n      onOpenChange(open);\n    },\n    open: !isDisabled && isOpen,\n    placement: 'bottom-start',\n    strategy: floatingStrategy ?? (isInsideDialog ? 'fixed' : 'absolute'),\n    whileElementsMounted: autoUpdate,\n  });\n\n  const click = useClick(context, { enabled: !isDisabled });\n  const dismiss = useDismiss(context);\n  const { getReferenceProps, getFloatingProps } = useInteractions([\n    click,\n    dismiss,\n  ]);\n\n  return {\n    context,\n    floatingStyles,\n    getFloatingProps,\n    getReferenceProps,\n    isPortaled,\n    refs,\n  };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,SAAgB,mBAAmB,EACjC,QACA,cACA,YACA,YAAY,gBACZ,oBAC4B;CAC5B,MAAM,iBAAiB,kBAAkB;CACzC,MAAM,aAAa,mBAAA,QAAA,mBAAA,KAAA,IAAA,iBAAkB,CAAC;CAItC,MAAM,mBAA6B,iBAAiB,CAAC,IAAI;CAEzD,MAAM,EAAE,MAAM,gBAAgB,YAAY,YAAY;EACpD,YAAY;GACV,OAAO,CAAC;GACR,KAAK;IAAE,oBAAoB,CAAC,WAAW;IAAG,SAAS;GAAE,CAAC;GACtD,MAAM;IAAE,UAAU;IAAkB,SAAS;GAAE,CAAC;GAChDA,KAAe;IACb,MAAM,EAAE,iBAAiB,UAAU,SAAS;KAG1C,SAAS,SAAS,MAAM,YACtB,kCACA,GAAG,MAAM,UAAU,MAAM,GAC3B;KACA,OAAO,OAAO,SAAS,SAAS,OAAO,EACrC,WAAW,GAAG,gBAAgB,IAChC,CAAC;IACH;IACA,UAAU;IACV,SAAS;GACX,CAAC;EACH;EACA,eAAe,SAAS;GACtB,aAAa,IAAI;EACnB;EACA,MAAM,CAAC,cAAc;EACrB,WAAW;EACX,UAAU,qBAAA,QAAA,qBAAA,KAAA,IAAA,mBAAqB,iBAAiB,UAAU;EAC1D,sBAAsB;CACxB,CAAC;CAED,MAAM,QAAQ,SAAS,SAAS,EAAE,SAAS,CAAC,WAAW,CAAC;CACxD,MAAM,UAAU,WAAW,OAAO;CAClC,MAAM,EAAE,mBAAmB,qBAAqB,gBAAgB,CAC9D,OACA,OACF,CAAC;CAED,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}