@advanced-rest-client/form-data-editor

中文文档
3.0.10发布于 2021/07/13Apache-2.0CommonJS近 30 天下载 3233

An element to edit form data (x-www-form-urlencoded)

原始使用文档
文档目录11 节
  1. <form-data-editor>
  2. Usage
  3. Installation
  4. In an html file
  5. In a LitElement
  6. Behaviour controls
  7. Generating view model from AMF model
  8. Development
  9. Running the demo locally
  10. Running the tests
  11. API components

Published on NPM

Tests and publishing

<form-data-editor>

An element to edit form data (x-www-form-urlencoded).

The element renders a form that allows to enter form data values.

It may be used with AMF json/ld model via api-view-model-transformer to transform AMF model to the data view model.

<form-data-editor value="grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb" allowcustom allowdisableparams allowhideoptional></form-data-editor>

Usage

Installation

npm install --save @advanced-rest-client/form-data-editor

In an html file

<html>
  <head>
    <script type="module">
      import '@advanced-rest-client/form-data-editor/form-data-editor.js';
    </script>
  </head>
  <body>
    <form-data-editor allowcustom allowdisableparams></form-data-editor>
    <script>
    {
      const editor = document.querySelector('api-url-params-editor');
      editor.onchange = (e) {
        console.log('Payload value', e.target.value); // or e.detail.value
      };
      editor.onmodel = (e) {
        console.log('View model', e.target.model); // or e.detail.value
      };
    }
    </script>
  </body>
</html>

In a LitElement

import { LitElement, html } from 'lit-element';
import '@advanced-rest-client/form-data-editor/form-data-editor.js';

class SampleElement extends PolymerElement {
  render() {
    return html`
    <form-data-editor
      .value="${this.payloadValues}"
      .model="${this.viewModel}"
      @value-changed="${this._valueHandler}"
      @model-changed="${this._modelHandler}"></form-data-editor>
    `;
  }

  _valueHandler(e) {
    this.payloadValues = e.detail.value;
  }

  _modelHandler(e) {
    this.viewModel = e.detail.value;
  }
}
customElements.define('sample-element', SampleElement);

Behaviour controls

allowDisableParams

When set it renders a checkbox next to each for item that allows to disable the item. The item is in the view and in generated data mode but is ignored when producing the value.

allowCustom

When set is renders "add parameter" button and allows to create new form value. Mandatory for stand-alone use.

allowHideOptional

When item.required model property is not set and this value is set then it hides all optional items (not marked as required) and renders a checkbox to render hidden items in the view.

<form-data-editor allowhideoptional></form-data-editor>
<script>
{
  document.querySelector('form-data-editor').model = [
    {
      name: 'param1',
      value: 'value1',
      required: true
    },
    {
      name: 'param2',
      value: 'value2',
      required: false
    }
  ];
}
</script>

This editor renders only param1 parameter and hides param2 form item. The user can render hidden items at any time.

Generating view model from AMF model

You can produce the view model from model generated by AMF parser via api-view-model-transformer element. This element produces common model for query parameters, URI parameters, body, and headers.

<api-view-model-transformer></api-view-model-transformer>
<form-data-editor></form-data-editor>

<script>
{
  const api = await generateApiModel();
  const endpoint = '/api-endpoint';
  const operation = 'GET';
  const bodyParametersModelArray = getOperationRequestBodyFromModel(api, endpoint, operation); // some abstract method
  const transformer = document.querySelector('api-view-model-transformer');
  transformer.api = api; // This is required to compute ld+json keys!
  const viewModel = transformer.computeViewModel(bodyParametersModelArray);
  document.querySelector('form-data-editor').model = viewModel;
}
</script>

Development

git clone https://github.com/advanced-rest-client/form-data-editor
cd form-data-editor
npm install

Running the demo locally

npm start

Running the tests

npm test

API components

This components is a part of API components ecosystem

版本与发布记录

@advanced-rest-client/form-data-editor 共发布 14 个版本,首次发布于 2019/02/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.10latest2021/07/135 年前
3.0.92021/07/015 年前
3.0.82021/06/115 年前
3.0.72019/11/206 年前
3.0.62019/11/126 年前
3.0.52019/10/317 年前

关于 @advanced-rest-client/form-data-editor 的常见问题

@advanced-rest-client/form-data-editor 是什么?

An element to edit form data (x-www-form-urlencoded)

如何安装 @advanced-rest-client/form-data-editor?

在项目目录运行 npm install @advanced-rest-client/form-data-editor,或使用 pnpm add / yarn add / bun add。

@advanced-rest-client/form-data-editor 支持 TypeScript 吗?

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

@advanced-rest-client/form-data-editor 支持 ESM 还是 CommonJS?

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

@advanced-rest-client/form-data-editor 可以商用吗?

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

@advanced-rest-client/form-data-editor 的下载量有多少?

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

@advanced-rest-client/form-data-editor 还在维护吗?

最新版本 3.0.10 发布于 2021/07/13(5 年前);至今共发布 14 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/02/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。