{"version":3,"file":"getPropsMerger.mjs","names":["ariaMergeProps","mergeRefs","mergeRefsFn"],"sources":["../../../../../../../src/lib/react/getPropsMerger.ts"],"sourcesContent":["import { mergeRefs as mergeRefsFn } from \"@react-aria/utils\";\nimport { mergeProps as ariaMergeProps } from \"@react-aria/utils\";\nimport { isObjectType, sortBy } from \"remeda\";\nimport { setProperty } from \"dot-prop\";\nimport type { Ref } from \"react\";\nimport { getNestingLevel } from \"@/lib/propsContext/nestedPropsContext/lib\";\n\ninterface MergePropsOptions {\n  mergeClassNames?: boolean;\n  mergeEventHandler?: boolean;\n  mergeRefs?: boolean;\n}\n\nexport const getPropsMerger =\n  (options: MergePropsOptions = {}): typeof ariaMergeProps =>\n  (...propsList) => {\n    const {\n      mergeClassNames = true,\n      mergeEventHandler = true,\n      mergeRefs = true,\n    } = options;\n\n    const sortedByLevel = sortBy(\n      propsList,\n      getNestingLevel,\n    ) as typeof propsList;\n\n    const mergedProps = ariaMergeProps(...sortedByLevel);\n\n    if (isObjectType(mergedProps)) {\n      if (!mergeClassNames) {\n        // \"Unmerge\" className\n        for (const props of sortedByLevel) {\n          if (\n            isObjectType(props) &&\n            \"className\" in mergedProps &&\n            \"className\" in props\n          ) {\n            mergedProps.className = props.className;\n          }\n        }\n      }\n\n      if (!mergeEventHandler) {\n        // \"Unmerge\" eventHandler\n        for (const props of sortedByLevel) {\n          if (isObjectType(props)) {\n            for (const [propName, propValue] of Object.entries(props)) {\n              const isEventHandlerProp = /^on[A-Z]/.test(propName);\n              if (isEventHandlerProp) {\n                setProperty(mergedProps, propName, propValue);\n              }\n            }\n          }\n        }\n      }\n\n      if (mergeRefs) {\n        const refProps = Object.keys(mergedProps).filter(\n          (p) => p === \"ref\" || p.endsWith(\"Ref\"),\n        );\n\n        for (const refProp of refProps) {\n          const collectedRefObjects = sortedByLevel\n            .map((p) => (isObjectType(p) && refProp in p ? p[refProp] : null))\n            // A ref nobody supplied contributes nothing. `undefined` used to\n            // survive this filter and merge into a callback ref — harmless for\n            // a ref the component attaches, fatal for one it reads instead\n            // (`anchorRef`, `triggerRef`): nothing ever calls the callback, so\n            // `.current` stays empty and the element is never found. Writing\n            // `anchorRef={condition ? ref : undefined}` was enough to hit it.\n            .filter((r): r is Ref<unknown> => r != null);\n\n          setProperty(\n            mergedProps,\n            refProp,\n            collectedRefObjects.length > 0\n              ? mergeRefsFn(...collectedRefObjects)\n              : undefined,\n          );\n        }\n      }\n    }\n\n    return mergedProps;\n  };\n"],"mappings":";;;;;;;AAaA,IAAa,kBACV,UAA6B,CAAC,OAC9B,GAAG,cAAc;CAChB,MAAM,EACJ,kBAAkB,MAClB,oBAAoB,MACpB,WAAA,cAAY,SACV;CAEJ,MAAM,gBAAgB,OACpB,WACA,eACF;CAEA,MAAM,cAAcA,WAAe,GAAG,aAAa;CAEnD,IAAI,aAAa,WAAW,GAAG;EAC7B,IAAI,CAAC,iBAEE;QAAA,MAAM,SAAS,eAClB,IACE,aAAa,KAAK,KAClB,eAAe,eACf,eAAe,OAEf,YAAY,YAAY,MAAM;EAAA;EAKpC,IAAI,CAAC,mBAEE;QAAA,MAAM,SAAS,eAClB,IAAI,aAAa,KAAK,GACf;SAAA,MAAM,CAAC,UAAU,cAAc,OAAO,QAAQ,KAAK,GAEtD,IAD2B,WAAW,KAAK,QACvC,GACF,YAAY,aAAa,UAAU,SAAS;GAAA;EAEhD;EAKN,IAAIC,aAAW;GACb,MAAM,WAAW,OAAO,KAAK,WAAW,CAAC,CAAC,QACvC,MAAM,MAAM,SAAS,EAAE,SAAS,KAAK,CACxC;GAEA,KAAK,MAAM,WAAW,UAAU;IAC9B,MAAM,sBAAsB,cACzB,KAAK,MAAO,aAAa,CAAC,KAAK,WAAW,IAAI,EAAE,WAAW,IAAK,CAAC,CAOjE,QAAQ,MAAyB,KAAK,IAAI;IAE7C,YACE,aACA,SACA,oBAAoB,SAAS,IACzBC,UAAY,GAAG,mBAAmB,IAClC,KAAA,CACN;GACF;EACF;CACF;CAEA,OAAO;AACT"}