UNPKG

@adobe/uxp-optimized

Version:

Library of react components optimized for Adobe's Unified Extensibility Platform

97 lines (96 loc) 3.57 kB
import "../common/ResizeObserver"; import Rect from "../common/Rect"; import { ReactElement } from "react"; import { ScrollToOptions } from "./VirtualizerApi"; export type ItemProperty<T extends object, V> = (item: T) => V; type ContainerProperties<T extends object> = { container: HTMLDivElement; horizontal: boolean; items: T[]; itemKey: ItemProperty<T, string>; itemType: ItemProperty<T, string>; itemRect?: ItemProperty<T, Rect>; renderKeys: string[]; setRenderKeys(value: string[]): void; onLayout?: () => void; }; /** * Used when scrolling to item with flow layout. * We don't really know the size of intervening items, * so we may have to correct scrollTop to keep item in view after sizing. */ type ScrollAnchor = { itemKey: string; itemPin: number; windowPin: number; duration: number; }; /** * This represents state which we cache permanently on the container. * Changes to this DO NOT force a react re-render. * By contrast changes to our react state does force a re-render. */ export default class VirtualManager<T extends object> { private resizeObserver; private container; private horizontal; private items; private itemLookup; private itemKey; private itemType; private itemRect?; private renderKeys; private setRenderKeys; private itemProperties; private classProperties; private containerPadding; private placeholder; private containerWidth; private scrollAnchor; private onLayout?; constructor(props: ContainerProperties<T>); update(props: ContainerProperties<T>): string[]; static getReactElements<T extends object>(items: T[], renderKeys: string[], itemKey: ItemProperty<T, string>, itemType: ItemProperty<T, string>, factory: (item: T) => ReactElement, cache: any): any[]; getItemRect(item: T | null, key: string): Rect | null; getItemRect(item: T, key?: string): Rect | null; isScrolling: boolean; updateAndLayout(forceLayout?: boolean): void; private layoutChildren; private getElementLookupByKey; private ensureElementsObservedAndSized; getVisibleRect(): Rect; get pageSize(): number; get prerenderOtherDirection(): number; get prerenderScrollDirection(): number; get isManualLayout(): boolean; private getRenderItemIndices; /** * Clip scrollTop - UXP should do this automatically, but it doesn't due to bug UXP-10612 * Can remove this once UXP bug is fixed * @returns number between 0 the container area - total area */ private getClippedScrollTarget; private getFocusedItemKey; private lastScrollTop; private scrollDirection; private previousItems?; private updateIndexes; onElementSized(element: HTMLElement): void; private onresize; getItemTargetScrollPosition(anchor: ScrollAnchor): number | null; scrollToItem(key: string, options?: ScrollToOptions): void; private scrollAnimating?; private scrollStartTime?; private scrollStartPosition?; private scrollDuration; private scrollWaitAfterFinish; private startScrollAnimation; private cancelScrollAnimation; private scrollAnimationCallback; private static readonly symbol; private getItemProperties; static instance<T extends object>(container: HTMLElement): VirtualManager<T> | undefined; static instance<T extends object>(container: HTMLElement, props: ContainerProperties<T>): VirtualManager<T>; static update<T extends object>(props: ContainerProperties<T>): string[]; } export {};