11'use client' ;
22import * as React from 'react' ;
33import { useIsoLayoutEffect } from '@base-ui/utils/useIsoLayoutEffect' ;
4- import { ReactStore } from '@base-ui/utils/store' ;
4+ import type { ReactStore } from '@base-ui/utils/store' ;
55import { isElement } from '@floating-ui/utils/dom' ;
66import { BaseUIChangeEventDetails } from '../../types' ;
77import { PopupStoreContext , PopupStoreSelectors , PopupStoreState } from '../../utils/popups' ;
88import { FloatingRootState , FloatingRootStore } from '../components/FloatingRootStore' ;
99
10+ /**
11+ * Narrowed to the store members this hook uses so consumers do not need to provide
12+ * unrelated store capabilities.
13+ */
14+ export type SyncedFloatingRootContextStore < State extends PopupStoreState < unknown > > = Pick <
15+ ReactStore < Readonly < State > , PopupStoreContext < never > , PopupStoreSelectors > ,
16+ 'context' | 'state' | 'useState' | 'useSyncedValue'
17+ > ;
18+
1019export interface UseSyncedFloatingRootContextOptions <
1120 State extends PopupStoreState < unknown > ,
12- ContextEventDetails extends BaseUIChangeEventDetails < string > ,
1321 OpenChangeEventDetails extends BaseUIChangeEventDetails < string > ,
1422> {
15- popupStore : ReactStore < State , PopupStoreContext < ContextEventDetails > , PopupStoreSelectors > ;
23+ popupStore : SyncedFloatingRootContextStore < State > ;
1624 /**
1725 * Whether the Popup element is passed to Floating UI as the floating element instead of the default Positioner.
1826 */
@@ -29,11 +37,8 @@ export interface UseSyncedFloatingRootContextOptions<
2937 */
3038export function useSyncedFloatingRootContext <
3139 State extends PopupStoreState < unknown > ,
32- ContextEventDetails extends BaseUIChangeEventDetails < string > ,
3340 OpenChangeEventDetails extends BaseUIChangeEventDetails < string > ,
34- > (
35- options : UseSyncedFloatingRootContextOptions < State , ContextEventDetails , OpenChangeEventDetails > ,
36- ) : FloatingRootStore {
41+ > ( options : UseSyncedFloatingRootContextOptions < State , OpenChangeEventDetails > ) : FloatingRootStore {
3742 const {
3843 popupStore,
3944 treatPopupAsFloatingElement = false ,
@@ -75,12 +80,20 @@ export function useSyncedFloatingRootContext<
7580 popupStore . useSyncedValue ( 'floatingId' , floatingId as State [ 'floatingId' ] ) ;
7681
7782 useIsoLayoutEffect ( ( ) => {
78- const valuesToSync : Partial < FloatingRootState > = {
83+ const valuesToSync = {
7984 open,
8085 floatingId,
8186 referenceElement,
8287 floatingElement,
83- } ;
88+ } as Pick <
89+ FloatingRootState ,
90+ | 'open'
91+ | 'floatingId'
92+ | 'referenceElement'
93+ | 'floatingElement'
94+ | 'domReferenceElement'
95+ | 'positionReference'
96+ > ;
8497
8598 if ( isElement ( referenceElement ) ) {
8699 valuesToSync . domReferenceElement = referenceElement ;
0 commit comments