{"version":3,"sources":["../../../src/components/List/useList.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport {\n  calculateListRole,\n  useListBase_unstable,\n  useListContextValues_unstable,\n  validateListItemElement,\n} from '@fluentui/react-list';\nimport { isSlot, SLOT_ELEMENT_TYPE_SYMBOL, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\n\nimport type { ListContextValues, ListProps, ListState } from './List.types';\nimport { getListFocusableElements, useCompositeListNavigation } from './listNavigation';\nimport { toDataAttributeValue } from '../../utils';\n\nexport { useListContext_unstable as useListContext } from '@fluentui/react-list';\n\n/**\n * Returns the state for a List component, given its props and ref.\n * The returned state can be modified with hooks before being passed to `renderList`.\n */\nexport const useList = (\n  props: ListProps,\n  ref: React.Ref<HTMLDivElement | HTMLUListElement | HTMLOListElement>,\n): ListState => {\n  const baseState = useListBase_unstable(props, ref);\n  const rootRef = React.useRef<HTMLDivElement | HTMLUListElement | HTMLOListElement>(null);\n  const mergedRef = useMergedRefs(baseState.root.ref, rootRef);\n  const onCompositeFocus = useCompositeListNavigation(baseState.navigationMode, rootRef);\n  const onFocusCapture: React.FocusEventHandler<HTMLElement> | undefined = baseState.root.onFocusCapture;\n  const handleFocusCapture: React.FocusEventHandler<HTMLElement> = useEventCallback(event => {\n    onFocusCapture?.(event);\n    onCompositeFocus(event);\n  });\n  const validateListItem = useEventCallback((element: HTMLElement) => {\n    if (baseState.navigationMode !== 'composite') {\n      baseState.validateListItem(element);\n      return;\n    }\n    if (process.env.NODE_ENV === 'production') {\n      return;\n    }\n    const root = baseState.root;\n    if (!isSlot(root) || typeof root[SLOT_ELEMENT_TYPE_SYMBOL] !== 'string') {\n      throw new Error('List must render an intrinsic root slot.');\n    }\n    validateListItemElement(element, {\n      listRenderedAs: root[SLOT_ELEMENT_TYPE_SYMBOL],\n      listRole: baseState.root.role || calculateListRole(baseState.navigationMode, !!baseState.selection),\n      hasSelection: !!baseState.selection,\n      hasFocusableChildren: getListFocusableElements(element).length > 0,\n    });\n  });\n\n  const state: ListState = {\n    ...baseState,\n    validateListItem,\n    root: {\n      ...baseState.root,\n      ref: mergedRef,\n      'data-list': '',\n      'data-navigation-mode': baseState.navigationMode,\n      'data-selectable': toDataAttributeValue(!!baseState.selection),\n      ...(baseState.navigationMode === 'items' && { focusgroup: 'toolbar block' }),\n      // Composite navigation owns the tab stop and key handling; a focusgroup would compete with it.\n      ...(baseState.navigationMode === 'composite' && {\n        focusgroup: undefined,\n        onFocusCapture: handleFocusCapture,\n      }),\n    },\n  };\n\n  return state;\n};\n\n/**\n * Maps the state of the list to the values that are passed through context to its children.\n */\nexport const useListContextValues: (state: ListState) => ListContextValues = useListContextValues_unstable;\n"],"names":["useList","useListContext","useListContext_unstable","useListContextValues","props","ref","baseState","useListBase_unstable","rootRef","React","useRef","mergedRef","useMergedRefs","root","onCompositeFocus","useCompositeListNavigation","navigationMode","onFocusCapture","handleFocusCapture","useEventCallback","event","validateListItem","element","process","env","NODE_ENV","isSlot","SLOT_ELEMENT_TYPE_SYMBOL","Error","validateListItemElement","listRenderedAs","listRole","role","calculateListRole","selection","hasSelection","hasFocusableChildren","getListFocusableElements","length","state","toDataAttributeValue","focusgroup","undefined","useListContextValues_unstable"],"mappings":"AAAA;;;;;;;;;;;;QAqBaA;eAAAA;;QANuBC;eAA3BC,kCAAuB;;QA+DnBC;eAAAA;;;;iEA5EU;2BAMhB;gCAC2E;gCAGb;uBAChC;AAQ9B,MAAMH,UAAU,CACrBI,OACAC;IAEA,MAAMC,YAAYC,IAAAA,+BAAoB,EAACH,OAAOC;IAC9C,MAAMG,UAAUC,OAAMC,MAAM,CAAuD;IACnF,MAAMC,YAAYC,IAAAA,6BAAa,EAACN,UAAUO,IAAI,CAACR,GAAG,EAAEG;IACpD,MAAMM,mBAAmBC,IAAAA,0CAA0B,EAACT,UAAUU,cAAc,EAAER;IAC9E,MAAMS,iBAAmEX,UAAUO,IAAI,CAACI,cAAc;IACtG,MAAMC,qBAA2DC,IAAAA,gCAAgB,EAAC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