# @constructor-io/constructorio-ui-plp 中文文档

规范地址：https://npmcn.com/package/%40constructor-io/constructorio-ui-plp/

版本：1\.21\.0
npm 元数据更新时间：2026-10-15T19:27:47.259Z
中文译文更新时间：2026-11-10T16:17:53.149Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40constructor-io/constructorio-ui-plp
原文对照：https://npmcn.com/package/%40constructor-io/constructorio-ui-plp/?lang=original
项目主页：https://github.com/Constructor-io/constructorio-ui-plp#readme
源码仓库：https://github.com/Constructor-io/constructorio-ui-plp

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：847 kB，282 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=20
- 运行依赖：1 个
- peer 依赖：react \>=16\.12\.0，tslib ^2\.4\.0，react-dom \>=16\.12\.0，@constructor-io/constructorio-ui-components ^1\.6\.0，@constructor-io/constructorio-client-javascript ^2\.77\.0
- 首次发布：2024-09-06T17:25:55.371Z
- 最新版本发布：2026-10-15T19:27:46.896Z
- 近 30 天下载量：6565（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：70（近 12 个月 29 个）

## 中文简介

用于网络应用程序的 PLP 用户界面库

## 安装

```sh
npm install @constructor-io/constructorio-ui-plp
```

也可以使用：`pnpm add @constructor-io/constructorio-ui-plp`、`yarn add @constructor-io/constructorio-ui-plp`、`bun add @constructor-io/constructorio-ui-plp`

## README

# PLP 界面库

[![npm](https://img.shields.io/npm/v/@constructor-io/constructorio-ui-plp)](https://www.npmjs.com/package/@constructor-io/constructorio-ui-plp) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Constructor-io/constructorio-ui-plp/blob/main/LICENSE)

## 导言

一个 UI 库,提供 React 组件来管理获取和渲染逻辑 [搜索](https://constructor.io/products/search/) 打开 [浏览](https://constructor.io/products/browse/) 由 Constructionor 驱动的产品列表页面。 已有打字支持.

我们 [故事书 Docs](https://constructor-io.github.io/constructorio-ui-plp/?path=/docs/general-introduction--documentation) 是探索此 UI 库的行为和可用配置选项的最佳场所.

## 安装

```bash
npm i @constructor-io/constructorio-ui-plp
```

## 使用量

### 使用反应组件

这个 `CioPlp` 组件处理整个PLP的状态管理、数据采集和渲染逻辑.

```jsx
import CioPlp from '@constructor-io/constructorio-ui-plp';

function YourComponent() {
  return (
    <div>
      <CioPlp apiKey='key_M57QS8SMPdLdLx4x' />
    </div>
  );
}
```

### 使用 Java 脚本套装

这是一种框架不可知论方法,可用于任何JavaScript项目. 这个 `CioPlp` 函数提供一个简单的接口,将整个 PLP 用户界面注入所提供 `selector`。 。 。 .

何况 [PLP 组件道具](https://constructor-io.github.io/constructorio-ui-plp/?path=/docs/components-cioplp--props),此函数也接受 `selector` 财务报告和审定财务报表 `includeCSS`。 。 。 .

```js
import CioPlp from '@constructor-io/constructorio-ui-plp/constructorio-ui-plp-bundled';

CioPlp({
  selector: '#plp-container',
  includeCSS: true, // Include the default CSS styles - defaults to true
  apiKey: 'key_M57QS8SMPdLdLx4x',
  // ... additional arguments
});
```

### ++ 存储- 特定默认值

当与 Shopify 主题合并时, 您可以使用 `useShopifyDefaults` 启用 Shopify 特定行为的道具 :

```jsx
<CioPlp apiKey='your-api-key' useShopifyDefaults={true} />
```

**它所提供的:**

-   `callbacks.onAddToCart`: 将产品添加到 Shopify 推车中 `/cart/add.js` API 密码
-   `callbacks.onProductCardClick`: 导航到 `/products/{itemId}`
-   `urlHelpers.setUrl`: 转换 `/group_id/` URL为 `/collections/` 用于购买兼容性

**对于 JavaScript 套装:**

使用时 `useShopifyDefaults` 用捆绑的版本,可以省略 `selector` 参数并默认为 `#cio-plp-ui-container`数字 :

```js
CioPlp({
  apiKey: 'your-api-key',
  useShopifyDefaults: true,
  // selector defaults to '#cio-plp-ui-container'
});
```

**说明:** 任何习惯 `callbacks` 或者说 `urlHelpers` 您提供将覆盖 Shopify 默认值.

## 自定义样式

### 库默认值

默认情况下, 从此库导入 React 组件不会将任何 CSS 拖入您的项目 .

如果您希望使用此库中的启动样式, 请添加一个类似于下面的示例导入语句的导入语句 :

```js
import '@constructor-io/constructorio-ui-plp/styles.css';
```

-   起动风格可以被用做在上方的地基上,或者作为完全被替换的参考.
-   要选择退出所有默认样式, 请不要导入 `styles.css` 样式表.
-   此库中的所有启动样式都在 `.cio-plp` CSS选取器.
-   启动样式是为了通过在自己的CSS规则中分层来扩展.
-   如果导入启动样式, `CioPlp` 组件将占用母容器的全部宽度和高度.

> 请注意启动样式使用 @ container 查询,并根据进取器的容器元素大小,为进取器提供响应样式。 由于这个功能得到了现代浏览器的支持,所以多填充没有被包含在这个库中. 然而,如果想要支持更老的浏览器,可以添加倒置样式或者使用一个 [多边填充](https://github.com/GoogleChromeLabs/container-query-polyfill)。 。 。 .

## 解决问题

### 已知问题

**旧的 Java 脚本环境**

图书馆提供两个不同的构件: C通JS (cjs)和ECMAScript模块 (mjs).

为ECMAScript模块(mjs)所建. JavaScript 版本是 ESNext, 它可能不会被您的环境所支持 . 如果情况如此,而你的环境正在使用一个更古老的JavaScript版本,如ES6(ES-2015),你可能会得到这个错误:

`Module parse failed: Unexpected token (15:32) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file`

要解决这个问题,您可以导入支持ES6(ES-2015)语法的普通JS(cjs)构建:

`import CioPlp from '@constructor-io/constructorio-ui-plp/cjs'`

**ESLint 语录**

ESLint有一个已知的问题,即它未能解决在互联网上暴露的路径 `exports` 国家防范机制一揽子措施声明。 如果您收到以下错误, 您可以使用 ESLint 安全禁用 `// eslint-disable-line` 为这条线.

`Unable to resolve path to module '@constructor-io/constructorio-ui-plp/styles.css'`

相关的未决问题: [问题1868](https://github.com/import-js/eslint-plugin-import/issues/1868), (中文(简体) ), [问题1810](https://github.com/import-js/eslint-plugin-import/issues/1810)

## 地方发展

### 开发脚本

```bash
npm ci                  # Install dependencies for local dev
npm run dev             # Start a local dev server for Storybook
npm run lint            # Run lint
```

### 图书馆维护

```bash
npm run compile           # Generate lib folder for publishing to npm
npm run build-storybook   # Generate Storybook static bundle for deploy with GitHub Pages
```

## 出版新版本

调度 [发布](https://github.com/Constructor-io/constructorio-ui-plp/actions/workflows/publish.yml) gitHub 动作中的工作流程 。 您必须提供两个论据:

-   **版本战略**数字 : `major`, (中文(简体) ), `minor`,或 `patch`。 。 。 .
-   **标题**:发布的标题.

此工作流程将自动 :

1.  使用所提供的策略跳出库版 .
2.  创建新 git 标签 .
3.  创建新的 GitHub 发布 .
4.  编译图书馆.
5.  向国家预防机制公布新版本.
6.  向 GitHub Pages 部署故事手册文件.
7.  汇报《公约》 [相关黑道](https://constructor.slack.com/archives/C061D3CFVR9)。 。 。 .

#### iQQ注意:请不要手动增加软件包. json版本或创建新的git标签.

库版通过发行和git标签来跟踪. 我们故意把包裹。 。 `0.0.0` 避免将变化推向 `main` 树枝。 这避免了分支保护规则例外的必要性,从而解决了许多安全关切.

## 新故事书版本

调度 [部署故事本](https://github.com/Constructor-io/constructorio-ui-plp/actions/workflows/deploy-storybook.yml) gitHub 动作中的工作流程 .

#### iQQQ 注:这在发布新版本时已经自动完成.

## 辅助文件

-   [童话书7 导言](https://storybook.js.org/docs/7.0/react/get-started/introduction)
-   [键入标记文件](https://www.typescriptlang.org/docs/)

## 常见问题

### @constructor-io/constructorio-ui-plp 是什么？

用于网络应用程序的 PLP 用户界面库

### 如何安装 @constructor-io/constructorio-ui-plp？

在项目目录运行 npm install @constructor-io/constructorio-ui-plp，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（\>=16\.12\.0）、tslib（^2\.4\.0）、react-dom（\>=16\.12\.0）、@constructor-io/constructorio-ui-components（^1\.6\.0）、@constructor-io/constructorio-client-javascript（^2\.77\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @constructor-io/constructorio-ui-plp 支持 TypeScript 吗？

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

### @constructor-io/constructorio-ui-plp 支持 ESM 还是 CommonJS？

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

### @constructor-io/constructorio-ui-plp 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=20。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @constructor-io/constructorio-ui-plp 可以商用吗？

@constructor-io/constructorio-ui-plp 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @constructor-io/constructorio-ui-plp 的下载量有多少？

根据 npm 官方下载统计，@constructor-io/constructorio-ui-plp 在 2026/10/11 – 2026/11/09 这 30 天内被下载 6,565 次，日均约 219 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @constructor-io/constructorio-ui-plp 还在维护吗？

最新版本 1\.21\.0 发布于 2026/10/16（25 天前）；至今共发布 70 个版本，其中过去 12 个月发布了 29 个；首次发布于 2024/09/07。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

