Sha256: f80046056657063ef73d579d94135acd16328425cc9f4390ff7a2d20db48eea2

Contents?: true

Size: 985 Bytes

Versions: 26

Compression:

Stored size: 985 Bytes

Contents

/**
 * Creates the next position for the active item considering a finite list of
 * items to be rendered on a page.
 */
export function finite({ active, pageSize, total, }) {
    const middle = Math.floor(pageSize / 2);
    if (total <= pageSize || active < middle)
        return active;
    if (active >= total - middle)
        return active + pageSize - total;
    return middle;
}
/**
 * Creates the next position for the active item considering an infinitely
 * looping list of items to be rendered on the page.
 */
export function infinite({ active, lastActive, total, pageSize, pointer, }) {
    if (total <= pageSize)
        return active;
    // Move the position only when the user moves down, and when the
    // navigation fits within a single page
    if (lastActive < active && active - lastActive < pageSize) {
        // Limit it to the middle of the list
        return Math.min(Math.floor(pageSize / 2), pointer + active - lastActive);
    }
    return pointer;
}

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.25 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.24 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.23 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.22 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.21 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.20 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.19 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.18 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.17 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.16 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.15 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.14 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.13 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.12 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.11 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.10 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.9 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.8 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs
clapton-0.0.7 lib/clapton/javascripts/node_modules/@inquirer/core/dist/esm/lib/pagination/position.mjs