/** * @typedef {object} PaginatePage * @property {Derived} items - The sliced items. Backed by * a `Derived`, so `fetch` may return a Promise; `items()` reports * the `nothing` sentinel while pending and the resolved array * afterwards. `await items` / `isResolved(items)` work as for any * derived. * @property {Derived} page - Writable raw page cursor * (1-based). `next`/`previous` and external code both write here; * reading returns the last value written, which may exceed * `totalPages` (intent is preserved across `numItems` / * `numPerPage` changes). * @property {SignalAccessor} currentPage - The page number * actually rendered, clamped to `[1, max(1, totalPages)]` * @property {SignalAccessor} totalPages - Amount of pages * @property {() => boolean} hasNext - Returns a boolean indicating if * has a next page * @property {() => void} next - To go to next page updating the items * @property {() => boolean} hasPrevious - Returns a boolean * indicating if has a previous page * @property {() => void} previous - To go to prev page updating the * items */ /** * Paginates `items` and provides "prev" and "next" functions to use * on pagination buttons * * @param {Accessor<{ values(): Iterable }>} items - List of * items to paginate * @param {Accessor} numPerPage - How many to display at the * same time * @param {Accessor} [page] - Optional source for the current * page (1-based). Same semantics as `paginate`'s `options.page`: * when an accessor reading a tracked signal is passed, source * updates clobber `next`/`previous` writes. * @returns {PaginatePage} * @url https://pota.quack.uy/use/paginate/paginateValues */ export function paginateValues(items: Accessor<{ values(): Iterable; }>, numPerPage: Accessor, page?: Accessor): PaginatePage; /** * Paginates items and provides "prev" and "next" functions to use on * pagination buttons * * @param {( * start: number, * end: number, * ) => unknown[] | Promise} fetch * ## !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!? * * Function to get items from. May return synchronously or as a * Promise; the `items` derived resolves accordingly. * @param {object} options * @param {Accessor} options.numPerPage - How many items are * displayed at the same time * @param {Accessor} options.numItems - How many items there * are in total * @param {Accessor} [options.page] - Optional source for the * current page (1-based). When passed an accessor that reads a * tracked signal (e.g. a URL search param), the derived re-runs on * change and clobbers any prior write from `next`/`previous`, * making the source the authority. * @returns {PaginatePage} * @url https://pota.quack.uy/use/paginate */ export function paginate(fetch: (start: number, end: number) => unknown[] | Promise, options: { numPerPage: Accessor; numItems: Accessor; page?: Accessor; }): PaginatePage; export type PaginatePage = { /** * - The sliced items. Backed by * a `Derived`, so `fetch` may return a Promise; `items()` reports * the `nothing` sentinel while pending and the resolved array * afterwards. `await items` / `isResolved(items)` work as for any * derived. */ items: Derived; /** * - Writable raw page cursor * (1-based). `next`/`previous` and external code both write here; * reading returns the last value written, which may exceed * `totalPages` (intent is preserved across `numItems` / * `numPerPage` changes). */ page: Derived; /** * - The page number * actually rendered, clamped to `[1, max(1, totalPages)]` */ currentPage: SignalAccessor; /** * - Amount of pages */ totalPages: SignalAccessor; /** * - Returns a boolean indicating if * has a next page */ hasNext: () => boolean; /** * - To go to next page updating the items */ next: () => void; /** * - Returns a boolean * indicating if has a previous page */ hasPrevious: () => boolean; /** * - To go to prev page updating the * items */ previous: () => void; }; //# sourceMappingURL=paginate.d.ts.map