@api-components/api-body-editor

中文文档
4.0.10发布于 2022/09/21Apache-2.0CommonJS近 30 天下载 3191

Renders different types of body editors. It works with AMF data model

原始使用文档
文档目录10 节
  1. Version compatibility
  2. Usage
  3. Installation
  4. In an html file
  5. In a LitElement
  6. Development
  7. Running the demo locally
  8. Running the tests
  9. API components
  10. Breaking Changes in v3

DEPRECATED

This component is deprecated. The code base has been moved to api-request module.


Renders body editor that correspond to selected media type.

It works with AMF data model to produce pre-populated view with values.

See breaking changes and list of required dependencies at the bottom of this document

Version compatibility

This version only works with AMF model version 2 (AMF parser >= 4.0.0). For compatibility with previous model version use 3.x.x version of the component.

Usage

Installation

npm install --save @api-components/api-body-editor

In an html file

<html>
  <head>
    <script type="module">
      import '@api-components/api-body-editor/api-body-editor.js';
    </script>
  </head>
  <body>
    <api-body-editor></api-body-editor>
    <script>
    {
      document.querySelector('api-body-editor').addEventListener('value-changed', (e) => {
        console.log(e.detail.value);
      });
    }
    </script>
  </body>
</html>

In a LitElement

import { LitElement, html } from 'lit-element';
import '@api-components/api-body-editor/api-body-editor.js';

class SampleElement extends PolymerElement {
  render() {
    return html`
    <api-body-editor
      allowdisableparams
      allowcustom
      allowhideoptional
      .contentType="${this.contentType}"
      @value-changed="${this._handleValue}"></api-headers-editor>
    `;
  }

  _handleValue(e) {
    this.bodyValue = e.target.value;
  }
}
customElements.define('sample-element', SampleElement);

Development

Running the demo locally

npm start

Running the tests

npm test

API components

This components is a part of API components ecosystem

Breaking Changes in v3

You need to include CodeMirror into the document before importing this element as it expect this global variable to be already set.

This is due CodeMirror not being able to run as ES module.

Use your build system to bundle CodeMirror into the build and don't forget to export global variable.

<!-- CodeMirror + modes loader -->
<script src="node_modules/codemirror/lib/codemirror.js"></script>
<script src="node_modules/codemirror/addon/mode/loadmode.js"></script>
<script src="node_modules/codemirror/mode/meta.js"></script>
<!--Default set of parsers, add as many as you need -->
<script src="node_modules/codemirror/mode/javascript/javascript.js"></script>
<script src="node_modules/codemirror/mode/xml/xml.js"></script>
<script src="node_modules/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<!-- JSON linter -->
<script src="node_modules/jsonlint/lib/jsonlint.js"></script>
<script src="node_modules/codemirror/addon/lint/lint.js"></script>
<script src="node_modules/codemirror/addon/lint/json-lint.js"></script>

Add linter popup styles:

<link rel="stylesheet" href="node_modules/codemirror/addon/lint/lint.css" />

Finally, you should set the path to CodeMirror modes. When content type change this path is used to load syntax highlighter. If you list all modes in the scripts above then this is not required.

<script>
CodeMirror.modeURL = 'node_modules/codemirror/mode/%N/%N.js';
</script>

The jsonlint library is a dependency of @api-components/code-mirror-linter already included in the dependency graph of this element.

版本与发布记录

@api-components/api-body-editor 共发布 20 个版本,首次发布于 2018/05/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.0.10latest2022/09/214 年前
4.0.92021/12/284 年前
4.0.72021/05/145 年前
4.0.62021/01/275 年前
4.0.52021/01/055 年前
4.0.42020/04/256 年前

关于 @api-components/api-body-editor 的常见问题

@api-components/api-body-editor 是什么?

Renders different types of body editors. It works with AMF data model

如何安装 @api-components/api-body-editor?

在项目目录运行 npm install @api-components/api-body-editor,或使用 pnpm add / yarn add / bun add。

@api-components/api-body-editor 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/api-components__api-body-editor 是否存在。

@api-components/api-body-editor 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@api-components/api-body-editor 可以商用吗?

@api-components/api-body-editor 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@api-components/api-body-editor 的下载量有多少?

根据 npm 官方下载统计,@api-components/api-body-editor 在 2026/10/06 – 2026/11/04 这 30 天内被下载 3,191 次,日均约 106 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@api-components/api-body-editor 还在维护吗?

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