• Stars
    star
    365
  • Rank 116,851 (Top 3 %)
  • Language
    TypeScript
  • License
    BSD 3-Clause "New...
  • Created about 5 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A file format for describing custom elements

custom-elements-manifest

A file format for describing custom elements.

The schema is published as a JSON Schema file, in schema.json. The schema is written in TypeScript (see schema.d.ts) and then compiled to JSON Schema.

Usage

Install:

npm i -D custom-elements-manifest

Require the JSON Schema:

const customElementManifestSchema = require('custom-elements-manifest');

Import the TypeScript types:

import * as schema from 'custom-elements-manifest/schema';

Referencing manifests from npm packages

In order to allow tools to find npm packages with custom element manifests without having to download package tarballs, packages should have a "customElements" field in their package.json that points to the manifest:

{
  "name": "example-package",
  "customElements": "custom-elements.json",
}

Schema Versioning

The schema has a schemaVersion field in the top-level object to facilitate evolution of the schema. The schema follows semver versioning, the current schema version is 2.0.0.

This version will not always match the npm package version, as some changes to the npm package might not have changes to the schema. We will publish a list of schema versions and their associated npm versions and git tags.

Example

Given the following source code in directory my-project:

my-project/my-element.js:

/**
 * This is the description of the class
 */
export class MyElement extends HTMLElement {
  static get observedAttributes() {
    return ['disabled'];
  }

  set disabled(val) {
    this.__disabled = val;
  }
  get disabled() {
    return this.__disabled;
  }

  fire() {
    this.dispatchEvent(new Event('disabled-changed'));
  }
}

customElements.define('my-element', MyElement);

The manifest would look like:

my-project/custom-elements.json:

{
  "schemaVersion": "2.0.0",
  "readme": "README.md",
  "modules": [
    {
      "kind": "javascript-module",
      "path": "my-project/my-element.js",
      "declarations": [
        {
          "kind": "class",
          "customElement": true,
          "name": "MyElement",
          "tagName": "my-element",
          "description": "This is the description of the class",
          "members": [
            {
              "kind": "field",
              "name": "disabled"
            },
            {
              "kind": "method",
              "name": "fire"
            }
          ],
          "events": [
            {
              "name": "disabled-changed",
              "type": {
                "text": "Event"
              }
            }
          ],
          "attributes": [
            {
              "name": "disabled"
            }
          ],
          "superclass": {
            "name": "HTMLElement"
          }
        }
      ],
      "exports": [
        {
          "kind": "js",
          "name": "MyElement",
          "declaration": {
            "name": "MyElement"
          }
        },
        {
          "kind": "custom-element-definition",
          "name": "my-element",
          "declaration": {
            "name": "MyElement"
          }
        }
      ]
    }
  ]
}

Motivation

Many tools need some machine-readable descriptions of custom elements: IDEs, documentation viewers, linters, graphical design tools, etc.

There have been several efforts in this area, including:

This repository is an effort to bring together tool owners to standardize on a common specification for a description format.

Use Cases

Editor Support

Developers using custom elements should be able to get full-featured IDE support including auto-completion, hover-documentation, unknown symbol warnings, etc. These features should be available in HTML files, and in various template syntaxes via template-specific tools.

Documentation and demos

Documentation viewers should be able to display all the relevant information about a custom element, such as its tag name, attributes, properties, definition module, CSS variables and parts, etc.

Using a custom-elements manifest, it would be easy to generate or display demos for your component using tools such as api-viewer-element, or automatically generate Storybook knobs for your components.

Linting

Linters should be able to produce warnings based on custom element defintions, such as warning if unknown elements are used in HTML templates.

Framework Integration

React currently is the only major framework where custom elements require some special handling. React will pass all data to a custom element in the form of HTML attributes, and cannot listen for DOM events coming from Custom Elements without the use of a workaround.

The solution for this is to create a wrapper React component that handles these things. Using a custom elements manifest, creation of these wrapper components could be automated.

Some component libraries like Fast or Shoelace provide specific instructions on how to integrate with certain frameworks. Automating this integration layer could make development easier for both authors of component libraries, but also for consumers of libraries.

Cataloging

A major use-case of custom elements manifests is that they allow us to reliably detect NPM packages that for certain contain custom elements. These packages could be stored, and displayed on a custom elements catalog, effectively a potential reboot of webcomponents.org. This catalog would be able to show rich demos and documentation of the custom elements contained in a package, by importing its components from a CDN like unpkg, and its custom elements manifest.

Testing

Tooling would be able to detect whether or not the public API of a custom element has changed, based on a snapshot of the current custom elements manifest file to decide the impact of an update, and potentially prevent breaking API change in patch versions.

More Repositories

1

webcomponentsjs

A suite of polyfills supporting the HTML Web Components specs
HTML
3,874
star
2

custom-elements-everywhere

Custom Element + Framework Interoperability Tests.
JavaScript
1,169
star
3

polyfills

Web Components Polyfills
HTML
1,137
star
4

gold-standard

1,029
star
5

webcomponents.github.io

WebComponents.org is where community-members document Web Components best practices
JavaScript
734
star
6

custom-elements

A polyfill for HTML Custom Elements v1
HTML
455
star
7

polymer-boilerplate

Fork this repo if you want to start your own Web Component using Polymer
HTML
369
star
8

webcomponents.org

Home of the web components community
TypeScript
366
star
9

react-integration

Converts web components into React components so that you can use them as first class citizens in your React components.
JavaScript
306
star
10

element-boilerplate

Fork this repo if you want to start your own Web Component using VanillaJS
HTML
271
star
11

shadycss

HTML
197
star
12

shadydom

ShadowDOM v1 shim
HTML
162
star
13

hello-world-element

Web Component example using VanillaJS
HTML
151
star
14

chrome-webcomponents-extension

Google Chrome extension to identify all Custom Elements used on a site
JavaScript
81
star
15

html-imports

HTML Imports polyfill
HTML
73
star
16

angular-interop

A demo of interoperability between Polymer and AngularJS
TypeScript
72
star
17

template

Minimal polyfill for <template>
HTML
69
star
18

hello-world-polymer

Web Component example using Polymer
HTML
58
star
19

xtag-boilerplate

Fork this repo if you want to start your own Web Component using X-Tag
HTML
52
star
20

sass-interop

A demo of interoperability between Sass and Polymer
CSS
46
star
21

slush-element

Slush generator to create Custom Elements using Polymer, X-Tag or VanillaJS
JavaScript
41
star
22

webcomponents-icons

Collection of high resolution Web Components icons for presentations, blog posts or whatever
CSS
40
star
23

template-shadowroot

TypeScript
38
star
24

community

A space for the webcomponents community
JavaScript
26
star
25

hello-world-xtag

Web Component example using X-Tag
HTML
24
star
26

webcomponents-platform

Very minimal platform related polyfills
JavaScript
23
star
27

less-interop

A demo of interoperability between Less and Polymer
CSS
20
star
28

webcomponents-lite

Web Components Polyfills minus Shadow DOM
JavaScript
16
star
29

wc-catalog

11
star
30

custom-elements-manifest-tools

Tools for working with custom elements manifests
TypeScript
7
star
31

apply-shim

Shim for CSS @apply mixins
JavaScript
5
star
32

.allstar

1
star