Virtualizer unstable
The arithmetic behind a virtual list: which items to render as the list scrolls, how much room to leave for the others, and where a scroll request puts the viewport.
A virtual list component keeps a Model, sends it the
Messages its host reports, such as the scroll offset and the
measured size of each rendered item, and draws what plan returns:
the ranges of items to render and the space to leave before, between and
after them. Nothing here reads a host. VirtualList in effect/ui/kit
draws a plan with the DOM, and VirtualList in @effect/ui-native/kit
with native views, so apps use one of those rather than this module.
Offsets and sizes are along the scroll axis, in the host's units, and are
measured from the start of the first item. height is the viewport's size
along that axis and width its size across it, whichever way the list
scrolls.
Constants
edgeThreshold
unstableHow close to an edge counts as at it when followEnd doesn't say.
Signature
declare const edgeThreshold: 1Constructors
The Model of a list that hasn't been laid out yet.
Signature
declare function init(props: { readonly count?: number; readonly dataset?: string; readonly followEnd?: boolean | { readonly behavior?: "instant" | "smooth"; readonly threshold?: number; }; readonly horizontal?: boolean; readonly initialCount?: number; readonly itemSize: number; readonly keys?: readonly Array<string>; readonly layout?: "flow" | "absolute"; readonly measure?: boolean; readonly overscan?: number; readonly reserveStart?: number; readonly scrollTo?: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; readonly sizes?: readonly Array<number>; readonly sticky?: readonly Array<number>; readonly trackScroll?: boolean;}): { readonly announced: { readonly atEnd: boolean; readonly atStart: boolean; readonly first: number; readonly height: number; readonly last: number; readonly length: number; readonly offset: number; readonly scrolling: boolean; } | null; readonly atEnd: boolean; readonly atStart: boolean; readonly dataset: string | null; readonly epoch: number; readonly focused: { readonly index: number; readonly key: string | null; } | null; readonly gap: number; readonly height: number; readonly lanes: number; readonly lead: number; readonly length: number; readonly offset: number; readonly overflowing: boolean; readonly position: { readonly index: number; readonly key: string | null; readonly offset: number; } | null; readonly scroll: { readonly done: boolean; readonly scrollTo: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; } | null; readonly scrolling: boolean; readonly sizes: { [key: string]: number; }; readonly width: number;}A Model restored from history: what was measured and the position, without the focus or a scroll in progress.
Signature
declare function restore<M extends { readonly announced: { readonly atEnd: boolean; readonly atStart: boolean; readonly first: number; readonly height: number; readonly last: number; readonly length: number; readonly offset: number; readonly scrolling: boolean; } | null; readonly atEnd: boolean; readonly atStart: boolean; readonly dataset: string | null; readonly epoch: number; readonly focused: { readonly index: number; readonly key: string | null; } | null; readonly gap: number; readonly height: number; readonly lanes: number; readonly lead: number; readonly length: number; readonly offset: number; readonly overflowing: boolean; readonly position: { readonly index: number; readonly key: string | null; readonly offset: number; } | null; readonly scroll: { readonly done: boolean; readonly scrollTo: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; } | null; readonly scrolling: boolean; readonly sizes: { [key: string]: number; }; readonly width: number;}>(model: M): MGetters
endThreshold
unstableHow close to the end counts as at the end while followEnd is on, or
null when it's off.
Signature
declare function endThreshold(props: { readonly count?: number; readonly dataset?: string; readonly followEnd?: boolean | { readonly behavior?: "instant" | "smooth"; readonly threshold?: number; }; readonly horizontal?: boolean; readonly initialCount?: number; readonly itemSize: number; readonly keys?: readonly Array<string>; readonly layout?: "flow" | "absolute"; readonly measure?: boolean; readonly overscan?: number; readonly reserveStart?: number; readonly scrollTo?: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; readonly sizes?: readonly Array<number>; readonly sticky?: readonly Array<number>; readonly trackScroll?: boolean;}): number | nullA scrollTo prop the Model hasn't recorded yet, to send back as
RequestedScroll.
Signature
declare function freshOf(model: { readonly announced: { readonly atEnd: boolean; readonly atStart: boolean; readonly first: number; readonly height: number; readonly last: number; readonly length: number; readonly offset: number; readonly scrolling: boolean; } | null; readonly atEnd: boolean; readonly atStart: boolean; readonly dataset: string | null; readonly epoch: number; readonly focused: { readonly index: number; readonly key: string | null; } | null; readonly gap: number; readonly height: number; readonly lanes: number; readonly lead: number; readonly length: number; readonly offset: number; readonly overflowing: boolean; readonly position: { readonly index: number; readonly key: string | null; readonly offset: number; } | null; readonly scroll: { readonly done: boolean; readonly scrollTo: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; } | null; readonly scrolling: boolean; readonly sizes: { [key: string]: number; }; readonly width: number;}, props: { readonly count?: number; readonly dataset?: string; readonly followEnd?: boolean | { readonly behavior?: "instant" | "smooth"; readonly threshold?: number; }; readonly horizontal?: boolean; readonly initialCount?: number; readonly itemSize: number; readonly keys?: readonly Array<string>; readonly layout?: "flow" | "absolute"; readonly measure?: boolean; readonly overscan?: number; readonly reserveStart?: number; readonly scrollTo?: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; readonly sizes?: readonly Array<number>; readonly sticky?: readonly Array<number>; readonly trackScroll?: boolean;}): { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; };} | nullThe key of the item at index, or null when the list has no keys.
Signature
declare function keyOf(props: { readonly count?: number; readonly dataset?: string; readonly followEnd?: boolean | { readonly behavior?: "instant" | "smooth"; readonly threshold?: number; }; readonly horizontal?: boolean; readonly initialCount?: number; readonly itemSize: number; readonly keys?: readonly Array<string>; readonly layout?: "flow" | "absolute"; readonly measure?: boolean; readonly overscan?: number; readonly reserveStart?: number; readonly scrollTo?: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; readonly sizes?: readonly Array<number>; readonly sticky?: readonly Array<number>; readonly trackScroll?: boolean;}, index: number): string | nullWorks out what to render for a Model and the props.
Signature
declare function plan(stored: { readonly announced: { readonly atEnd: boolean; readonly atStart: boolean; readonly first: number; readonly height: number; readonly last: number; readonly length: number; readonly offset: number; readonly scrolling: boolean; } | null; readonly atEnd: boolean; readonly atStart: boolean; readonly dataset: string | null; readonly epoch: number; readonly focused: { readonly index: number; readonly key: string | null; } | null; readonly gap: number; readonly height: number; readonly lanes: number; readonly lead: number; readonly length: number; readonly offset: number; readonly overflowing: boolean; readonly position: { readonly index: number; readonly key: string | null; readonly offset: number; } | null; readonly scroll: { readonly done: boolean; readonly scrollTo: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; } | null; readonly scrolling: boolean; readonly sizes: { [key: string]: number; }; readonly width: number;}, props: { readonly count?: number; readonly dataset?: string; readonly followEnd?: boolean | { readonly behavior?: "instant" | "smooth"; readonly threshold?: number; }; readonly horizontal?: boolean; readonly initialCount?: number; readonly itemSize: number; readonly keys?: readonly Array<string>; readonly layout?: "flow" | "absolute"; readonly measure?: boolean; readonly overscan?: number; readonly reserveStart?: number; readonly scrollTo?: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; readonly sizes?: readonly Array<number>; readonly sticky?: readonly Array<number>; readonly trackScroll?: boolean;}): PlanThe key the Model keeps the size of the item at index under.
Signature
declare function sizeKey(props: { readonly count?: number; readonly dataset?: string; readonly followEnd?: boolean | { readonly behavior?: "instant" | "smooth"; readonly threshold?: number; }; readonly horizontal?: boolean; readonly initialCount?: number; readonly itemSize: number; readonly keys?: readonly Array<string>; readonly layout?: "flow" | "absolute"; readonly measure?: boolean; readonly overscan?: number; readonly reserveStart?: number; readonly scrollTo?: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; readonly sizes?: readonly Array<number>; readonly sticky?: readonly Array<number>; readonly trackScroll?: boolean;}, index: number): stringWhere a request puts the viewport's start, or null when its item isn't
in the list.
Signature
declare function targetOf(stored: { readonly announced: { readonly atEnd: boolean; readonly atStart: boolean; readonly first: number; readonly height: number; readonly last: number; readonly length: number; readonly offset: number; readonly scrolling: boolean; } | null; readonly atEnd: boolean; readonly atStart: boolean; readonly dataset: string | null; readonly epoch: number; readonly focused: { readonly index: number; readonly key: string | null; } | null; readonly gap: number; readonly height: number; readonly lanes: number; readonly lead: number; readonly length: number; readonly offset: number; readonly overflowing: boolean; readonly position: { readonly index: number; readonly key: string | null; readonly offset: number; } | null; readonly scroll: { readonly done: boolean; readonly scrollTo: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; } | null; readonly scrolling: boolean; readonly sizes: { [key: string]: number; }; readonly width: number;}, props: { readonly count?: number; readonly dataset?: string; readonly followEnd?: boolean | { readonly behavior?: "instant" | "smooth"; readonly threshold?: number; }; readonly horizontal?: boolean; readonly initialCount?: number; readonly itemSize: number; readonly keys?: readonly Array<string>; readonly layout?: "flow" | "absolute"; readonly measure?: boolean; readonly overscan?: number; readonly reserveStart?: number; readonly scrollTo?: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; readonly sizes?: readonly Array<number>; readonly sticky?: readonly Array<number>; readonly trackScroll?: boolean;}, scrollTo: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; };}): number | nullThe request that is waiting to be scrolled to, if any.
Signature
declare function waitingOf(model: { readonly announced: { readonly atEnd: boolean; readonly atStart: boolean; readonly first: number; readonly height: number; readonly last: number; readonly length: number; readonly offset: number; readonly scrolling: boolean; } | null; readonly atEnd: boolean; readonly atStart: boolean; readonly dataset: string | null; readonly epoch: number; readonly focused: { readonly index: number; readonly key: string | null; } | null; readonly gap: number; readonly height: number; readonly lanes: number; readonly lead: number; readonly length: number; readonly offset: number; readonly overflowing: boolean; readonly position: { readonly index: number; readonly key: string | null; readonly offset: number; } | null; readonly scroll: { readonly done: boolean; readonly scrollTo: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; } | null; readonly scrolling: boolean; readonly sizes: { [key: string]: number; }; readonly width: number;}, props: { readonly count?: number; readonly dataset?: string; readonly followEnd?: boolean | { readonly behavior?: "instant" | "smooth"; readonly threshold?: number; }; readonly horizontal?: boolean; readonly initialCount?: number; readonly itemSize: number; readonly keys?: readonly Array<string>; readonly layout?: "flow" | "absolute"; readonly measure?: boolean; readonly overscan?: number; readonly reserveStart?: number; readonly scrollTo?: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; readonly sizes?: readonly Array<number>; readonly sticky?: readonly Array<number>; readonly trackScroll?: boolean;}): { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; };} | nullModels
The alignment of a requested item within the viewport.
"nearest" leaves an item that is in full view where it is, and otherwise
brings in its nearest edge.
Signature
declare const Align: Literals<readonly ["start", "center", "end", "nearest"]>The alignment of a requested item within the viewport.
Signature
type Align = typeof Align.TypeThe span of offsets a row covers. start is null for the first row and
end for the last, since they reach past the list's edges.
Signature
declare const Bounds: NullOr<Struct<{ readonly end: NullOr<Number>; readonly start: NullOr<Number>;}>>The span of offsets a row covers.
Signature
type Bounds = typeof Bounds.TypeThe events of a virtual list.
Details
Scrolled reports first and last, the first and last visible items,
atStart and atEnd, whether the list is scrolled to its start and to
its end, and scrolling, whether it's scrolling. It also reports
offset, how far the viewport's start is past the start of the first
item, in the units of an Offset scroll target, height, the viewport's
size, and length, the list's size from the start of its first item.
It's emitted when first, last, atStart, atEnd or scrolling
changes, and with trackScroll also when offset, height or length
does.
Signature
declare const Events: TaggedEnum<{ Scrolled: TaggedStruct<"Scrolled", { readonly atEnd: Boolean; readonly atStart: Boolean; readonly first: Number; readonly height: Number; readonly last: Number; readonly length: Number; readonly offset: Number; readonly scrolling: Boolean; }>;}>The events of a virtual list.
Signature
type Events = typeof Events.TypeAn item by index, and by key when the list has keys.
Signature
declare const ItemRef: Struct<{ readonly index: Number; readonly key: NullOr<String>;}>An item by index, and by key when the list has keys.
Signature
type ItemRef = typeof ItemRef.TypeMeasuredItem
unstableA rendered item as its host measured it: top and size along the scroll
axis from the start of the first item, and left across it.
Signature
declare const MeasuredItem: Struct<{ readonly index: Number; readonly key: NullOr<String>; readonly left: Number; readonly size: Number; readonly top: Number;}>A rendered item as its host measured it.
Signature
type MeasuredItem = typeof MeasuredItem.TypeWhat a host reports to a virtual list.
Details
MovedViewport: the viewport's start, size and edges, the item at its start when the host knows it, and the request the host has just scrolled to, if any.RequestedScroll: a request taken fromscrollTo, so it's kept after the prop is dropped.ScrolledByUser: the user scrolled, which drops a waiting request.MeasuredItems: the sizes of rendered items, for theepochthey were rendered in, and the width they were laid out at. A new width drops the sizes measured before.FocusedItemandBlurredItems: the item that holds the focus, which stays rendered.ScrolledViewport: the scroll offset, viewport size and length, and whether a scroll is going on.
Signature
declare const Message: TaggedEnum<{ BlurredItems: TaggedStruct<"BlurredItems", {}>; FocusedItem: TaggedStruct<"FocusedItem", { readonly index: Number; readonly key: NullOr<String>; }>; MeasuredItems: TaggedStruct<"MeasuredItems", { readonly epoch: Number; readonly items: $Array<Struct<{ readonly index: Number; readonly key: NullOr<String>; readonly left: Number; readonly size: Number; readonly top: Number; }>>; readonly width: Number; }>; MovedViewport: TaggedStruct<"MovedViewport", { readonly anchor: NullOr<Struct<{ readonly index: Number; readonly key: NullOr<String>; readonly offset: Number; }>>; readonly atEnd: Boolean; readonly atStart: Boolean; readonly height: Number; readonly length: Number; readonly overflowing: Boolean; readonly scrolled: NullOr<Struct<{ readonly align: optional<Literals<readonly ["start", "center", "end", "nearest"]>>; readonly behavior: optional<Literals<readonly ["instant", "smooth"]>>; readonly id: optional<Union<readonly [String, Number]>>; readonly target: TaggedEnum<{ End: TaggedStruct<"End", {}>; Index: TaggedStruct<"Index", { readonly index: ...; }>; Key: TaggedStruct<"Key", { readonly key: ...; }>; Offset: TaggedStruct<"Offset", { readonly offset: ...; }>; }>; }>>; readonly start: Number; }>; RequestedScroll: TaggedStruct<"RequestedScroll", { readonly scrollTo: Struct<{ readonly align: optional<Literals<readonly ["start", "center", "end", "nearest"]>>; readonly behavior: optional<Literals<readonly ["instant", "smooth"]>>; readonly id: optional<Union<readonly [String, Number]>>; readonly target: TaggedEnum<{ End: TaggedStruct<"End", {}>; Index: TaggedStruct<"Index", { readonly index: Number; }>; Key: TaggedStruct<"Key", { readonly key: String; }>; Offset: TaggedStruct<"Offset", { readonly offset: Number; }>; }>; }>; }>; ScrolledByUser: TaggedStruct<"ScrolledByUser", {}>; ScrolledViewport: TaggedStruct<"ScrolledViewport", { readonly height: Number; readonly length: Number; readonly offset: Number; readonly scrolling: Boolean; }>;}>What a host reports to a virtual list.
Signature
type Message = typeof Message.TypeThe state of a virtual list: its scroll position and viewport, the sizes measured so far, the focused item and the latest scroll request.
Signature
declare const Model: Struct<{ readonly announced: NullOr<Struct<{ readonly atEnd: Boolean; readonly atStart: Boolean; readonly first: Number; readonly height: Number; readonly last: Number; readonly length: Number; readonly offset: Number; readonly scrolling: Boolean; }>>; readonly atEnd: Boolean; readonly atStart: Boolean; readonly dataset: NullOr<String>; readonly epoch: Number; readonly focused: NullOr<Struct<{ readonly index: Number; readonly key: NullOr<String>; }>>; readonly gap: Number; readonly height: Number; readonly lanes: Number; readonly lead: Number; readonly length: Number; readonly offset: Number; readonly overflowing: Boolean; readonly position: NullOr<Struct<{ readonly index: Number; readonly key: NullOr<String>; readonly offset: Number; }>>; readonly scroll: NullOr<Struct<{ readonly done: Boolean; readonly scrollTo: Struct<{ readonly align: optional<Literals<readonly ["start", "center", "end", "nearest"]>>; readonly behavior: optional<Literals<readonly ["instant", "smooth"]>>; readonly id: optional<Union<readonly [String, Number]>>; readonly target: TaggedEnum<{ End: TaggedStruct<"End", {}>; Index: TaggedStruct<"Index", { readonly index: ...; }>; Key: TaggedStruct<"Key", { readonly key: ...; }>; Offset: TaggedStruct<"Offset", { readonly offset: ...; }>; }>; }>; }>>; readonly scrolling: Boolean; readonly sizes: $Record<String, Number>; readonly width: Number;}>The state of a virtual list.
Signature
type Model = typeof Model.TypeWhat a host draws for a list: the items to render, the space to leave for the others, and the scroll request to apply.
Details
items: the indices to render, in order. They're in one range around the viewport,window, from its first index up to its end, and more ranges for the focused item and the activestickyitem when they're outside it.before,gapsandafter: the space before the first item, before each later range by its first index, and after the last item.total: the list's length.firstandlast: the offsets the first and last visible rows cover. While the viewport's start and end stay within them, the same items are visible.fresh: ascrollToprop the Model hasn't recorded yet, to send back asRequestedScroll.request: the request to scroll to, resolved.waitingistruewhile a request is waiting, even one whose item isn't in the list yet.
Signature
interface Plan { readonly after: number; readonly before: number; readonly count: number; readonly epoch: number; readonly first: { readonly end: number | null; readonly start: number | null; } | null; readonly fresh: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; } | null; readonly gap: number; readonly gaps: ReadonlyMap<number, number>; readonly items: Array<number>; readonly lanes: number; readonly last: { readonly end: number | null; readonly start: number | null; } | null; readonly offsetOf: (index: number) => number; readonly request: { readonly index: number | null; readonly offset: number | null; readonly scrollTo: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; } | null; readonly total: number; readonly waiting: boolean; readonly window: readonly [number, number];}A scroll position as the item at the viewport's start and how far into it the viewport starts, so it holds when the items before it change size.
Signature
declare const Position: Struct<{ readonly index: Number; readonly key: NullOr<String>; readonly offset: Number;}>A scroll position as an item and an offset into it.
Signature
type Position = typeof Position.TypeThe props every virtual list takes. A kit adds the props of its host.
Signature
declare const Props: Struct<{ readonly count: optional<Number>; readonly dataset: optional<String>; readonly followEnd: optional<Union<readonly [Boolean, Struct<{ readonly behavior: optional<Literals<readonly ["instant", "smooth"]>>; readonly threshold: optional<Number>; }>]>>; readonly horizontal: optional<Boolean>; readonly initialCount: optional<Number>; readonly itemSize: Number; readonly keys: optional<$Array<String>>; readonly layout: optional<Literals<readonly ["flow", "absolute"]>>; readonly measure: optional<Boolean>; readonly overscan: optional<Number>; readonly reserveStart: optional<Number>; readonly scrollTo: optional<Struct<{ readonly align: optional<Literals<readonly ["start", "center", "end", "nearest"]>>; readonly behavior: optional<Literals<readonly ["instant", "smooth"]>>; readonly id: optional<Union<readonly [String, Number]>>; readonly target: TaggedEnum<{ End: TaggedStruct<"End", {}>; Index: TaggedStruct<"Index", { readonly index: Number; }>; Key: TaggedStruct<"Key", { readonly key: String; }>; Offset: TaggedStruct<"Offset", { readonly offset: Number; }>; }>; }>>; readonly sizes: optional<$Array<Number>>; readonly sticky: optional<$Array<Number>>; readonly trackScroll: optional<Boolean>;}>The props every virtual list takes.
Signature
type Props = typeof Props.TypeScrollRequest
unstableA scroll request with its target resolved: the item's index, or the
offset. Both are null for the end.
Signature
declare const ScrollRequest: Struct<{ readonly index: NullOr<Number>; readonly offset: NullOr<Number>; readonly scrollTo: Struct<{ readonly align: optional<Literals<readonly ["start", "center", "end", "nearest"]>>; readonly behavior: optional<Literals<readonly ["instant", "smooth"]>>; readonly id: optional<Union<readonly [String, Number]>>; readonly target: TaggedEnum<{ End: TaggedStruct<"End", {}>; Index: TaggedStruct<"Index", { readonly index: Number; }>; Key: TaggedStruct<"Key", { readonly key: String; }>; Offset: TaggedStruct<"Offset", { readonly offset: Number; }>; }>; }>;}>A scroll request with its target resolved.
Signature
type ScrollRequest = typeof ScrollRequest.TypeScrollTarget
unstableWhere a scroll request goes: an item by index or by key, a distance from the start of the list, or the end of the list.
Signature
declare const ScrollTarget: TaggedEnum<{ End: TaggedStruct<"End", {}>; Index: TaggedStruct<"Index", { readonly index: Number; }>; Key: TaggedStruct<"Key", { readonly key: String; }>; Offset: TaggedStruct<"Offset", { readonly offset: Number; }>;}>Where a scroll request goes.
Signature
type ScrollTarget = typeof ScrollTarget.TypeA scroll request. A list scrolls once for each request that differs from
the last one it received, so change id to go to the same target again.
Signature
declare const ScrollTo: Struct<{ readonly align: optional<Literals<readonly ["start", "center", "end", "nearest"]>>; readonly behavior: optional<Literals<readonly ["instant", "smooth"]>>; readonly id: optional<Union<readonly [String, Number]>>; readonly target: TaggedEnum<{ End: TaggedStruct<"End", {}>; Index: TaggedStruct<"Index", { readonly index: Number; }>; Key: TaggedStruct<"Key", { readonly key: String; }>; Offset: TaggedStruct<"Offset", { readonly offset: Number; }>; }>;}>A scroll request.
Signature
type ScrollTo = typeof ScrollTo.TypeA Model after an update, and the events to emit.
Signature
interface Updated<M extends Model> { readonly events: readonly Array<{ readonly _tag: "Scrolled"; readonly atEnd: boolean; readonly atStart: boolean; readonly first: number; readonly height: number; readonly last: number; readonly length: number; readonly offset: number; readonly scrolling: boolean; }>; readonly model: M;}Predicates
Whether two offsets or sizes are the same, give or take half a unit.
Signature
declare function same(a: number, b: number): booleansameScrollTo
unstableWhether two scroll requests are the same.
Signature
declare const sameScrollTo: (a: ScrollTo, b: ScrollTo) => booleansameTracked
unstableWhether two reports of the scroll offset, viewport size and length are the same.
Signature
declare function sameTracked(a: { readonly height: number; readonly length: number; readonly offset: number;}, b: { readonly height: number; readonly length: number; readonly offset: number;}): booleanWhether offset falls within bounds, give or take half a unit.
Signature
declare function within(bounds: { readonly end: number | null; readonly start: number | null;} | null, offset: number): booleanUpdates
Applies a message to the Model, keeping any fields a kit adds to it.
Signature
declare function update<M extends { readonly announced: { readonly atEnd: boolean; readonly atStart: boolean; readonly first: number; readonly height: number; readonly last: number; readonly length: number; readonly offset: number; readonly scrolling: boolean; } | null; readonly atEnd: boolean; readonly atStart: boolean; readonly dataset: string | null; readonly epoch: number; readonly focused: { readonly index: number; readonly key: string | null; } | null; readonly gap: number; readonly height: number; readonly lanes: number; readonly lead: number; readonly length: number; readonly offset: number; readonly overflowing: boolean; readonly position: { readonly index: number; readonly key: string | null; readonly offset: number; } | null; readonly scroll: { readonly done: boolean; readonly scrollTo: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; } | null; readonly scrolling: boolean; readonly sizes: { [key: string]: number; }; readonly width: number;}>(stored: M, props: { readonly count?: number; readonly dataset?: string; readonly followEnd?: boolean | { readonly behavior?: "instant" | "smooth"; readonly threshold?: number; }; readonly horizontal?: boolean; readonly initialCount?: number; readonly itemSize: number; readonly keys?: readonly Array<string>; readonly layout?: "flow" | "absolute"; readonly measure?: boolean; readonly overscan?: number; readonly reserveStart?: number; readonly scrollTo?: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; }; readonly sizes?: readonly Array<number>; readonly sticky?: readonly Array<number>; readonly trackScroll?: boolean;}, message: { readonly _tag: "MovedViewport"; readonly anchor: { readonly index: number; readonly key: string | null; readonly offset: number; } | null; readonly atEnd: boolean; readonly atStart: boolean; readonly height: number; readonly length: number; readonly overflowing: boolean; readonly scrolled: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; } | null; readonly start: number;} | { readonly _tag: "RequestedScroll"; readonly scrollTo: { readonly align?: "start" | "end" | "center" | "nearest"; readonly behavior?: "instant" | "smooth"; readonly id?: string | number; readonly target: { readonly _tag: "Offset"; readonly offset: number; } | { readonly _tag: "End"; } | { readonly _tag: "Index"; readonly index: number; } | { readonly _tag: "Key"; readonly key: string; }; };} | { readonly _tag: "ScrolledByUser";} | { readonly _tag: "MeasuredItems"; readonly epoch: number; readonly items: readonly Array<{ readonly index: number; readonly key: string | null; readonly left: number; readonly size: number; readonly top: number; }>; readonly width: number;} | { readonly _tag: "BlurredItems";} | { readonly _tag: "ScrolledViewport"; readonly height: number; readonly length: number; readonly offset: number; readonly scrolling: boolean;} | { readonly _tag: "FocusedItem"; readonly index: number; readonly key: string | null;}): Updated<M>Utils
alignedStart
unstableWhere the viewport starts to show the span from top to bottom as
align says, given that it starts at view and is height long.
Signature
declare function alignedStart(top: number, bottom: number, view: number, height: number, align: "start" | "end" | "center" | "nearest"): number