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

yy-virtual-list

v1.0.8

Published

web components virtual list

Downloads

4

Readme

Component properties

| property | explain | type | default | | ----------------------- | --------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------------- | | estimated-height | estimate the height of each item | number | 50 | | height-fixed | whether the height of each item is fixed? If true, the true height will not be obtained. The estimated-height shall prevail | number | false | | buffer | number of virtual list buffers | number | 4 | | page | page number | number | 1 | | size | pageSize | number | 10 | | request | getting data | Function | ()=>{} | | built-in | Whether to use built-in list notation | boolean | false | | container-styles-string | Container css Styles | string | height:50vh;background:#f5f5f5;margin:1rem; |

Component slots

| slot name | explain | | --------- | ------------ | | loading | data loading | | loaded | data loaded | | empty | data empty |

Component method

| name | explain | type | | ------- | --------------------------------- | -------- | | refresh | refresh the list keep page, size | Function | | reload | refresh the list reset page, size | Function |

Examples of Use

vue

<!-- @format -->

<template>
  <div class="demo">
    <div @click="onReload">reload</div>
    <yy-virtual-list id="virtualListId" ref="yyEl" :estimatedItemSize="192" @change="virtualListChange" :request="fetchDemo" style="--containerHeight: 50vh">
      <div class="card" v-for="item in virtualList" :key="item._index" :id="item._index">
        <div class="inner">
          <div>{{ item.index }}</div>
          <div>{{ item.name }}</div>
          <div>{{ item.email }}</div>
        </div>
      </div>
    </yy-virtual-list>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue"
import "yy-virtual-list"

const fetchDemo = async (page: number, size: number) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      const data = []
      for (let i = 0; i < size; i++) {
        data.push({
          index: (page - 1) * size + i + 1,
          name: `name${page}`,
          email: `email${i}@email.com`,
        })
      }
      resolve(data)
    }, Math.random() * 1000)
  })
}

const virtualList = ref([] as any)
const virtualListChange = (val: any) => {
  virtualList.value = val.detail
}
const yyEl = ref()
const onReload = () => {
  yyEl.value?.reload()
}
</script>
<style>
:root {
  --containerHeight: 30vh;
}
.card {
  padding: 1rem;
  color: #fff;
}
.inner {
  background: #3c3c3c;
  border-radius: 20px;
  padding: 0.5rem;
}
</style>

vite 去除自定义标签警告

 plugins: [
    vue({
      template: {
        compilerOptions: {
          // 将所有带yy短横线的标签名都视为自定义元素
          isCustomElement: (tag) => tag.includes('yy-virtual-list'),
        },
      },
    }),
  ],

html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script type="module" src="/src/index.ts"></script>
    <style>
      .loading {
        color: red;
        text-align: center;
      }
    </style>
  </head>

  <body>
    <div onclick="reload()">reload</div>
    <yy-virtual-list
      built-in="true"
      container-styles-string="
    height:80vh;background:#f5f5f5;margin:1rem;border-radius:20px
    "
    >
      <yy-template>
        <style>
          .card{
            padding:1rem;box-size;color:#fff;
          }
          .inner{background:#3C3C3C; border-radius: 20px;padding: 0.5rem;}
        </style>
        <div class="card">
          <div class="inner">
            <strong>${this.index}</strong>
            <strong>${this.name}</strong>
            is
            <div class="te">${this.email}</div>
          </div>
        </div>
      </yy-template>
      <div slot="loading" class="loading">~loading~</div>
    </yy-virtual-list>
  </body>
  <script>
    // 模拟数据
    const fetchDemo = (page, size) => {
      if (page === 3) {
        return []
      }
      return new Promise((resolve) => {
        setTimeout(() => {
          const data = []
          for (let i = 0; i < size; i++) {
            data.push({
              index: (page - 1) * size + i + 1,
              name: `name${page}`,
              email: `email${i}@email.com`,
            })
          }
          resolve(data)
        }, Math.random() * 1000)
      })
    }
    const el = document.getElementsByTagName("yy-virtual-list")[0]
    // 添加自定义属性 request
    el.setAttribute("request", fetchDemo)
    const reload = () => {
      console.log("reload")
      el.reload()
    }
  </script>
</html>