import { Node } from './node'; import { Section } from './section'; import { StatefulEventBus } from './stateful-event-bus'; import type { BaseProps, ScrollDirection, Size, WaterFlowProps } from './interface'; export type RootProps = Pick & Required>; type RootState = { /** 是否在滚动中 */ isScrolling: boolean; /** 滚动偏移量 */ scrollOffset: number; /** * 滚动方向 * * - forward 向下滚动 * * - backward 向上滚动 */ scrollDirection: ScrollDirection; /** 滚动高度 */ scrollHeight: number; /** 容器的尺寸信息 */ containerSize: Size; /** 渲染的分组区间范围 */ renderRange: [number, number]; }; export declare const RootEvents: { ReachUpperThreshold: symbol; ReachLowerThreshold: symbol; Resize: symbol; AllSectionsLayouted: symbol; InitialRenderCompleted: symbol; }; type Events = keyof typeof RootEvents; /** * 数据模型继承自有状态的事件总线,便于在节点之间通信,以及通过 useSyncExternalStore 关联 React 视图 */ export declare class Root extends StatefulEventBus { /** * 瀑布流根节点唯一标识 */ id: string; /** * 分组映射表,便于查找分组 */ sectionMap: Map; /** * 节点映射表,便于查找节点 */ nodeMap: Map; /** * 分组列表,基于计算出的渲染的分组区间范围 sections.slice(start, end + 1) 进行渲染 */ sections: Section[]; /** * 设置预加载的 Item 条数。 */ cacheCount: number; upperThresholdCount: number; lowerThresholdCount: number; /** * 触发滚动阈值对应的 scrollTop 值 */ upperThresholdScrollTop: number; /** * 触发滚动阈值对应的 scrollTop 值 */ lowerThresholdScrollTop: number; constructor(props: RootProps); /** * 设置订阅事件 */ private setupSubscriptions; /** * 渐进式渲染 * * 因为初始没法知道每个分组的高度信息,不知道渲染边界,所以需要渐进式渲染 * * 当目前的渲染批次的首个分组的scrollTop大于容器的高度,说明容器可视区域已经填满,没必要再往下渲染了 * * @param [i=0] 从第几个分组开始渲染 * */ renderInitialLayout(i?: number): void; /** * 计算滚动阈值对应的 scrollTop 并设置 upperThresholdScrollTop * 当距顶部还有 upperThresholdCount 个 FlowItem 时的 scrollTop 值 */ private setUpperThresholdScrollTop; /** * 计算滚动阈值对应的 scrollTop 并设置 lowerThresholdScrollTop * 当距底部还有 lowerThresholdCount 个 FlowItem 时的 scrollTop 值 */ private setLowerThresholdScrollTop; /** * 处理滚动到阈值的情况 * 检测当前滚动位置是否达到了上下阈值,并触发相应的事件 */ private handleReachThreshold; /** * 容器的滚动上边界 */ get scrollBoundaryStart(): number; /** * 容器的滚动下边界 */ get scrollBoundaryEnd(): number; /** * 计算每个section的底部位置 * * sectionBottomRange = [ [section1.top, section1.bottom], [section2.top, section2.bottom], ..., [sectionN.top, sectionN.bottom] ] * * @returns [number,number][] */ get sectionRange(): number[][]; /** * 计算滚动高度 */ updateScrollHeight(): void; /** * 注册分组 */ registerSection(section: Section): void; /** * 注册节点 */ registerNode(node: Node): void; /** * 查找分组 */ findSection(id: string): Section; /** * 查找节点 */ findNode(id: string): Node; /** * 获取分组渲染区间 */ getSectionRenderRange(): [number, number]; /** * 计算预渲染的分组个数 */ private calcCacheSection; } export {};