npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-window

v1.2.5

Published

Svelte components for efficiently rendering large, scrollable lists and tabular data. Port of react-window to Svelte.

Downloads

715

Readme

svelte-window

Svelte components for efficiently rendering large, scrollable lists and tabular data. Port of react-window to Svelte.

Svelte window works by only rendering part of a large data set (just enough to fill the viewport). This helps address some common performance bottlenecks:

  1. It reduces the amount of work (and time) required to render the initial view and to process updates.
  2. It reduces the memory footprint by avoiding over-allocation of DOM nodes.

NPM license

Install

npm install --save-dev svelte-window

Usage

This library is a port of react-window, here are some examples: react-window.now.sh.

This is how to render a basic list:

<script>
    import { FixedSizeList as List, styleString as sty } from 'svelte-window';
</script>
<List
height={150}
itemCount={1000}
itemSize={35}
width={300}
let:items>
    {#each items as it (it.key)}
        <div style={sty(it.style)}>Row {it.index}</div>        
    {/each}
</List>

Here is another example with a fixed size grid with a scroll-to button, scrolling indicators:

<script>
  import { FixedSizeGrid as Grid, styleString as sty } from 'svelte-window'

  let grid

  const click = () => {
    if (grid) {
      grid.scrollToItem({
        align: 'start',
        columnIndex: 150,
        rowIndex: 300,
      })
    }
  }
</script>

<Grid
  bind:this={grid}
  columnCount={1000}
  columnWidth={100}
  height={150}
  rowCount={1000}
  rowHeight={35}
  width={300}
  useIsScrolling
  let:items>
  {#each items as it (it.key)}
    <div style={sty(it.style)}>
      {it.isScrolling ? 'Scrolling' : `Row ${it.rowIndex} - Col ${it.columnIndex}`}
    </div>
  {/each}
</Grid>

<button on:click={click}> To row 300, column 150 </button>

SvelteKit

SvelteKit is in public beta, so a 100% compatibility cannot be guaranteed. Since version 1.2.0 svelte-window should work with SvelteKit when imported as a devDependency (npm i --save-dev svelte-window). By design, svelte-window is a client side library. Normal components like FixedSizeList need to be guarded from server-side-rendering (eg. with a {#if mounted}... clause). For convenience, there are SSR counterparts to all four components, which handle guarding within the library: FixedSizeListSSR, FixedSizeGridSSR, VariableSizeListSSR, VariableSizeGridSSR. In the examples above, just change eg.:

<script>
    import { FixedSizeList as List, styleString as sty } from 'svelte-window';
</script>
...

to

<script>
    import { FixedSizeListSSR as List, styleString as sty } from 'svelte-window';
</script>
...

Bundle Size

If you don't use all of svelte-windows components on a page, you can minimize the bundle size by using direct imports from the lib folder. Eg. you can change imports like this

import { FixedSizeListSSR as List, styleString as sty } from 'svelte-window';

to

import List from 'svelte-window/lib/FixedSizeListSSR.svelte';
import {styleString as sty} from 'svelte-window/src/styleString';

Differences to the React library

  1. Grids and lists don't actively render the children. Instead, an array of item information is passed down via item props. You can use the let:item to access it and render with the each block.
  2. Styles are passed down as objects, like in the React library, but Svelte only accepts strings for style. A helper function styleString is exported from svelte-window, to convert the style object to string
  3. Variable sized variants have utilities to reset the cache, when row/cell sizes change. These are not directly added to the class, but to a member called instance. Eg. instead of
list.resetAfterIndex(...)

use

list.instance.resetAfterIndex(...)

Affected functions:

VariableSizeList:

  • resetAfterIndex

VariableSizeGrid:

  • resetAfterIndices
  • resetAfterColumnIndex
  • resetAfterRowIndex

Related libraries

More information

Here is a blog post about how the library was ported from React to Svelte.