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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@21epub/antd-resource-lib

v1.0.1

Published

基于 antd 5、jotai 与 ky 的素材库组件与工具集,支持 Modal 与 Panel 两种形态,并使用 `@tanstack/react-query` 获取与缓存数据。

Readme

resource-lib

基于 antd 5、jotai 与 ky 的素材库组件与工具集,支持 Modal 与 Panel 两种形态,并使用 @tanstack/react-query 获取与缓存数据。

安装

请确保安装以下依赖(版本以项目为准):

  • antd 5
  • jotai 2
  • ky 1
  • @tanstack/react-query 4
  • react ≥ 16.14

快速开始

  1. 全局样式与 Provider

在应用入口引入 antd 5 的重置样式,并使用 Jotai 与 React Query 的 Provider 包裹应用:

import 'antd/dist/reset.css'
import React from 'react'
import { createRoot } from 'react-dom/client'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { AssetsContext, AssetsModal } from '@21epub/resource-lib'

const queryClient = new QueryClient()

const App = () => (
  <AssetsContext>
    <QueryClientProvider client={queryClient}>
      {/* 你的应用 */}
      <AssetsModal />
    </QueryClientProvider>
  </AssetsContext>
)

createRoot(document.getElementById('root')!).render(<App />)
  1. 打开素材选择(Modal)

通过库内置的 useInsertAssets 打开组件并在回调中接收素材:

import React, { useEffect } from 'react'
import { AssetsModal, useInsertAssets } from '@21epub/resource-lib'

export default function Demo() {
  const insertAssets = useInsertAssets({
    type: 'image',
    multiple: true,
    onInsert: (assets) => {
      console.log('selected assets', assets)
    },
  })

  useEffect(() => {
    insertAssets()
  }, [insertAssets])

  return <AssetsModal />
}
  1. 面板形态(Panel)
import React from 'react'
import { AssetsPanel } from '@21epub/resource-lib'

export default () => <AssetsPanel pubicLibraryVisible assetRemovable />

组件 Props 摘要

  • AssetsModal、AssetsPanel 共同支持:
    • pubicLibraryVisible: 是否显示公共素材
    • psdImporterVisible: 是否显示 PSD 导入(仅 Modal 支持 PSD 按钮)
    • assetRemovable: 是否允许删除素材
    • uploadCompressible: 是否允许压缩素材
    • onReceive: 上传前拦截文件
    • onUploaded: 上传完成回调

数据与网络

  • 请求由 ky 发起,默认前缀为 /v3/api/material/
  • 本仓库在本地开发与 Storybook 中通过代理转发到后端(见 .storybook/middleware.js)。如果在你的应用中使用,请配置相同的代理或由网关统一转发该前缀。

在 Storybook 中调试

  • 全局在 .storybook/preview.js 中注入了 antd 样式与 Providers(Jotai、React Query)。
  • 已在 .storybook/middleware.js 内设置了 /v2/v3 的 API 代理。
  • 直接运行脚本:npm run storybook

从 Recoil 迁移

  • 旧版 AssetsRecoilRootuseAssetsModalState 已替换为 Jotai 与 useInsertAssets
  • 现在需要用 AssetsContext(Jotai Provider 的 re-export)与 QueryClientProvider 包裹应用。