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

kv-input

v1.3.1

Published

Simple key-value editor web-component

Downloads

1

Readme

kv-input

The simple key-value editor web-component.

Demo page

Quick start

Install

npm install --save kv-input

Add HTML and JavaScript

Use component tag:

<kv-input></kv-input>

Include component library into your project:

import '/node_modules/kv-input/kv-input.js';

And subscribe to changes:

const kvInput = document.querySelector('kv-input');
kvInput.onchange = (resultObject) => {
    console.log(resultObject);
} 

That's it :)

Tag attributes

  • title - allows to set a title for whole component, empty by default
  • key-title - a title for key-column, empty by default
  • value-title - a title for value-column, empty by default
  • debounce - time in milliseconds before the component will handle a change, 300ms by default
  • use-types - use checkboxes instead of the boolean values and restore types into returned object (otherwise values will be returned as strings), true by default.
  • meta - json to define a dropdown content
  • keys - list of keys allowed to select, json or comma-separated string

Passing data inside tag

It is possible to pass initial data inside of the component tag:

<kv-input>{"Put here": "JSON", "It will be parsed": "via JSON.parse"}</kv-input>

The second way is to use names slots:

<kv-input>
    <style>.title {color: navy}</style>
    <p slot="json">{"init":"value"}</p>
    <p slot="meta">{"init":["key","value"]}</p>
</kv-input>

There are four possible slots right now:

  • json - json to set key-values
  • meta - json to set meta-data
  • keys - json to set allowed key names
  • style or tag <style> - allows you to pass custom styles into the component, see Styling section.

Note, that all <style> tags from inside of the component will be removed.

Note, that it is possible to process only one value per slot name, so you are not able to set several styles, or several meta-data.

Interaction

kv getter/setter

The kv property allows to set the data into component, or to read the modified object.

// set data
kvInput.kv = plainObject;

// read data
plainObject = kvInput.kv;

meta getter/setter

Also, it is possible to set some meta-information to make dropdown for defined keys like this:

kvInput.meta = {test: ['some', 'selectable', 'values']};

or like this:

<kv-input meta='{"JSON":["will","be","parsed"]}'></kv-input>

or as named slot:

<kv-input>
    <p slot="meta">{"JSON":["will","be","parsed"]}</p>
</kv-input>

keys getter/setter

Same for keys property. You can get or set list of keys that will be rendered as dropdown to restrict input key names.

direct property usage:

kvInput.keys = ['some', 'selectable', 'keys'];

attribute:

<kv-input keys="some, selectable, values"></kv-input>

or same slot usage as above.

HotKeys

Ctrl+Y deletes the pair.

Ctrl+Click on checkbox or dropdown transform them into text-input.

Ctrl+Alt+D duplicates the pair.

ArrowUp and ArrowDown to move cursor between rows.

Styling

You can pass styles inside to the component. Here is the sample structure of component:

+-------------------------------------------------------------------------+
| h3.title.main-title                                                     |
+-----------------------------------+-------------------------------------+
| span.title.column-title.key-title | span.title.column-title.value-title |
+-----------------------------------+-------------------------------------+
| input.key.input                   | input.value.input                   |
+-----------------------------------+-------------------------------------+
| input.key.input.invalid           | input[type=checkbox].value.input    |
+-----------------------------------+-------------------------------------+
| input.key.input                   | select.value.input                  |
+-----------------------------------+-------------------------------------+

And you can use this classes to customize the view:

| Selector | Description | | --- | --- | | .title | All three titles | | .main-title or h3 | Main title, passed by title attribute | | .column-title or span | Two column header titles | | .key-title | Title for key-column, passed by key-title attribute | | .value-title | Title for value-column, passed by value-title attribute | | .input | All inputs | | .key | Inputs in key-column | | .value | Inputs in value-column | | .invalid | Duplicated keys |

Browsers compatibility

Not right now, sorry.

Tested in latest Chrome.