@evershop/editorjs-product-list

中文文档
1.0.0发布于 2026/06/25MITTypeScriptESM + CJS近 30 天下载 4588

Product List Tool for EverShop — pick, reorder and remove a list of products inside Editor.js

原始使用文档
文档目录5 节
  1. How it works
  2. Usage
  3. Config
  4. Saved data
  5. Develop

Product List Tool for EverShop

A Editor.js block tool that lets an editor build an ordered list of products: search & add, remove, and drag-reorder them. Each card shows the product thumbnail, name, SKU, price, stock and status.

It is a sibling of @evershop/editorjs-image and follows the same conventions (Vite library build, CSS injected by JS, @codexteam/icons).

How it works

The tool ships its own search modal. It stays GraphQL-agnostic: you give it a searchProducts(keyword, { page, limit }) function and it handles the search box, debouncing, pagination, multi-select and the selected-state UI. In EverShop that function runs the admin products(filters: [...]) query. On the storefront the saved snapshot is rendered with EverShop's <ProductList/> component.

Usage

import ProductListTool from "@evershop/editorjs-product-list";

const editor = new EditorJS({
  tools: {
    productList: {
      class: ProductListTool,
      config: {
        defaultColumns: 4,
        pageSize: 20,
        searchProducts: async (keyword, { page, limit }) => {
          const res = await fetch(`/api/products?q=${keyword}&page=${page}&limit=${limit}`);
          const { items, total } = await res.json();
          return { items, total }; // items: ProductItem[]
        },
      },
    },
  },
});

Config

OptionTypeDescription
searchProducts(keyword: string, opts: { page: number; limit: number }) => Promise<{ items, total }>Data source for the built-in search modal.
defaultColumnsnumberStorefront grid columns for new blocks (default 4).
pageSizenumberPage size for the search modal (default 20).
onSelectProducts(current: ProductItem[], onSelect: (products: ProductItem[]) => void) => voidOptional override — supply your own picker instead of the built-in modal. Takes precedence.
placeholderstringEmpty-state text.

Saved data

{
  "type": "productList",
  "data": {
    "columns": 4,
    "products": [
      {
        "productId": 1,
        "uuid": "…",
        "sku": "TSHIRT-RED-M",
        "name": "Cool T-Shirt",
        "url": "/cool-t-shirt",
        "image": { "url": "…", "alt": "…" },
        "price": { "regular": { "value": 29, "text": "$29.00" }, "special": { "value": 19, "text": "$19.00" } },
        "inStock": true,
        "status": 1
      }
    ]
  }
}

sku is the stable identifier (matching EverShop's ProductSelector and the products(filters: [{ key: "sku", operation: in, value: "…" }]) query).

Develop

npm install
npm run dev    # opens dev/index.html with a mocked host picker
npm run build  # emits dist/product-list.{mjs,umd.js} + index.d.ts

Based on the Image Block for Editor.js.

版本与发布记录

@evershop/editorjs-product-list 共发布 1 个版本,首次发布于 2026/06/25;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.0.0latest2026/06/254 个月前

关于 @evershop/editorjs-product-list 的常见问题

@evershop/editorjs-product-list 是什么?

Product List Tool for EverShop — pick, reorder and remove a list of products inside Editor.js

如何安装 @evershop/editorjs-product-list?

在项目目录运行 npm install @evershop/editorjs-product-list,或使用 pnpm add / yarn add / bun add。

@evershop/editorjs-product-list 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@evershop/editorjs-product-list 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@evershop/editorjs-product-list 可以商用吗?

@evershop/editorjs-product-list 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@evershop/editorjs-product-list 的下载量有多少?

根据 npm 官方下载统计,@evershop/editorjs-product-list 在 2026/10/14 – 2026/11/12 这 30 天内被下载 4,588 次,日均约 153 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@evershop/editorjs-product-list 还在维护吗?

最新版本 1.0.0 发布于 2026/06/25(4 个月前);至今共发布 1 个版本,其中过去 12 个月发布了 1 个;首次发布于 2026/06/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。