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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@api-components/api-body-editor

v4.0.10

Published

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

Downloads

1,920

Readme

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.