{"version":3,"file":"useAsyncCacheKey.mjs","names":[],"sources":["../../src/async/useAsyncCacheKey.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { ValueEditorProps, VersatileSelectorProps } from '../types';\nimport type { UseAsyncOptionListParams } from './types';\n\n/**\n * Generates a cache key given the same props and params as {@link useAsyncOptionList}.\n *\n * @group Hooks\n */\nexport const useAsyncCacheKey = <PropsType extends VersatileSelectorProps | ValueEditorProps>(\n  props: PropsType,\n  // v8 ignore next\n  { getCacheKey }: UseAsyncOptionListParams<PropsType> = {}\n): string => {\n  const ruleOrGroup = props.rule ?? (props as VersatileSelectorProps).ruleGroup;\n\n  return useMemo(\n    () =>\n      typeof getCacheKey === 'string'\n        ? (ruleOrGroup?.[getCacheKey as 'id'] ?? '')\n        : typeof getCacheKey === 'function'\n          ? getCacheKey(props)\n          : Array.isArray(getCacheKey) && getCacheKey.length > 0 && ruleOrGroup\n            ? getCacheKey.map(ck => `${ruleOrGroup[ck as 'id']}`).join('|')\n            : '',\n    [\n      getCacheKey,\n      // Spread all properties of `props`—in alphabetical order—to allow passing `props`\n      // to `getCacheKey` function without having `props` in the dependency array.\n      // oxlint-disable react/use-memo, react/exhaustive-deps\n      ...Object.keys(props)\n        .toSorted()\n        .map(k => props[k as keyof PropsType]),\n      // oxlint-enable react/use-memo, react/exhaustive-deps\n    ]\n  );\n};\n"],"mappings":";;;;;;;AASA,MAAa,oBACX,OAEA,EAAE,gBAAqD,CAAC,MAC7C;CACX,MAAM,cAAc,MAAM,QAAS,MAAiC;CAEpE,OAAO,cAEH,OAAO,gBAAgB,WAClB,cAAc,gBAAwB,KACvC,OAAO,gBAAgB,aACrB,YAAY,KAAK,IACjB,MAAM,QAAQ,WAAW,KAAK,YAAY,SAAS,KAAK,cACtD,YAAY,KAAI,OAAM,GAAG,YAAY,KAAa,CAAC,CAAC,KAAK,GAAG,IAC5D,IACV,CACE,aAIA,GAAG,OAAO,KAAK,KAAK,CAAC,CAClB,SAAS,CAAC,CACV,KAAI,MAAK,MAAM,EAAqB,CAEzC,CACF;AACF"}