MCPcopy Index your code
hub / github.com/adobe/react-spectrum / TreeInner

Function TreeInner

packages/react-aria-components/src/Tree.tsx:403–657  ·  view source on GitHub ↗
({props, collection, treeRef: ref}: TreeInnerProps<T>)

Source from the content-addressed store, hash-verified

401}
402
403function TreeInner<T>({props, collection, treeRef: ref}: TreeInnerProps<T>) {
404 const {dragAndDropHooks} = props;
405 let {direction} = useLocale();
406 let collator = useCollator({usage: 'search', sensitivity: 'base'});
407 let hasDragHooks = !!dragAndDropHooks?.useDraggableCollectionState;
408 let hasDropHooks = !!dragAndDropHooks?.useDroppableCollectionState;
409 let dragHooksProvided = useRef(hasDragHooks);
410 let dropHooksProvided = useRef(hasDropHooks);
411
412 useEffect(() => {
413 if (dragHooksProvided.current !== hasDragHooks) {
414 console.warn(
415 'Drag hooks were provided during one render, but not another. This should be avoided as it may produce unexpected behavior.'
416 );
417 }
418 if (dropHooksProvided.current !== hasDropHooks) {
419 console.warn(
420 'Drop hooks were provided during one render, but not another. This should be avoided as it may produce unexpected behavior.'
421 );
422 }
423 }, [hasDragHooks, hasDropHooks]);
424 let {
425 selectionMode = 'none',
426 expandedKeys: propExpandedKeys,
427 defaultExpandedKeys: propDefaultExpandedKeys,
428 onExpandedChange,
429 disabledBehavior = 'all'
430 } = props;
431 let {
432 CollectionRoot,
433 isVirtualized,
434 layoutDelegate,
435 dropTargetDelegate: ctxDropTargetDelegate
436 } = useContext(CollectionRendererContext);
437
438 // Kinda annoying that we have to replicate this code here as well as in useTreeState, but don't want to add
439 // flattenCollection stuff to useTreeState. Think about this later
440 let [expandedKeys, setExpandedKeys] = useControlledState(
441 propExpandedKeys ? new Set(propExpandedKeys) : undefined,
442 propDefaultExpandedKeys ? new Set(propDefaultExpandedKeys) : new Set(),
443 onExpandedChange
444 );
445
446 let [lastCollection, setLastCollection] = useState(collection);
447 let [lastExpandedKeys, setLastExpandedKeys] = useState(expandedKeys);
448 let [flattenedCollection, setFlattenedCollection] = useState(() =>
449 collection.withExpandedKeys(lastExpandedKeys, expandedKeys)
450 );
451
452 // if the lastExpandedKeys is not the same as the currentExpandedKeys or the collection has changed, then run this
453 if (!areSetsEqual(lastExpandedKeys, expandedKeys) || collection !== lastCollection) {
454 setFlattenedCollection(collection.withExpandedKeys(lastExpandedKeys, expandedKeys));
455 setLastCollection(collection);
456 setLastExpandedKeys(expandedKeys);
457 }
458
459 let state = useTreeState({
460 ...props,

Callers

nothing calls this directly

Calls 15

useLocaleFunction · 0.90
useCollatorFunction · 0.90
useControlledStateFunction · 0.90
useTreeStateFunction · 0.90
useTreeFunction · 0.90
useFocusRingFunction · 0.90
useRenderPropsFunction · 0.90
filterDOMPropsFunction · 0.90
mergePropsFunction · 0.90
useDndPersistedKeysFunction · 0.90
useRenderDropIndicatorFunction · 0.90
areSetsEqualFunction · 0.85

Tested by

no test coverage detected