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 🙏

© 2026 – Pkg Stats / Ryan Hefner

code-sample-editor

v0.1.0-pre.4

Published

A multi-file code editor component with live preview

Readme

code-sample-editor

A multi-file code editor component with live preview

Introduction

<code-sample-editor> is a web component that allows you to embed multi-file, editable, live-preview code examples that use JavaScript, TypeScript, HTML and CSS. It's like a mini-IDE that you can embed many times in a page, and it works without a server!

Features

No server-required

<code-sample-editor> uses a service worker to send files from the main page to the preview iframe. Users can edit examples locally and the edited files are served to the iframe without ever hitting the network. This means you can use <code-sample-editor> with a static file server, and preview reloads are ultra-fast!

Multi-file unbundled editing

<code-sample-editor> serves each file indivdually to the preview iframe, instead of bundling them first. This gives faster refresh times and means taht you can utilize the standard web platform features in your examples without a bundler getting in the way and potentially breaking things. The experience is very much like working wtih a static file server.

HTML can have multiple <script> and <link> tags, even dynamically added. CSS can use @import and url(). JavaScript can use import.meta.url, dynamic import(), and fetch(). It all just works.

Bare-module specifiers support

Standard JavaScript modules are great, but currently they lack one feature that has such overwhelming use and utility that we included support for it: base module specifiers.

If you import a module by name, like:

import {html, render} from 'lit-html';

<code-sample-editor> will automatically rewrite the import specifier to use unpkg.com URLs:

import {html, render} from 'https://unpkg.com/lit-html?module';

TypeScript support

Besides standard JavaScript, <code-sample-editor> supports TypeScript files, which are automatically transpiled to JavaScript in a web worker.

The TypeScript worker behaves exactly like the tsc compiler does, so the examples match local code. This means that when you import other TypeScript files, you do with with a .js extension, which matches the compiler output.

my-element.ts

import {LitElement, html, customElement} from 'lit-element';

@customElement('my-element')
class MyElement extends LitElement { /* ... */ }

index.html

<script type="module" src="my-element.js"></script>

Note the filename of my-element.js.

Inline or external sources

You can define an example entirely in HTML for simplicity:

<code-sample-editor>
  <script type="sample/html" filename="index.html">
    <script type="module" src="my-element.js">&lt;/script>
    <h1>Hello World!</h1>
    <my-element></my-element>
  </script>
  <script type="sample/js" filename="my-element.js">
    import {LitElement, html, customElement} from 'lit-element';

    class MyElement extends LitElement { /* ... */ }
    customElements.define('my-element', MyElement);
  </script>
</code-sample-editor>

Or define your project in a JSON manifest:

<code-sample-editor project-src="./example-1.json"></code-sample-editor>

example-1.json:

{
  "files": {
    "index.html": {},
    "my-element.js": {},
    "my-second-element.js": {}
  }
}

Getting Started

Install with npm:

npm i code-sample-editor

Load the component definition:

<script
  type="module" 
  src="/node_modules/code-sample-editor/lib/code-sample-editor.js">
</script>

Use the component:

<code-sample-editor project-src="./example-1.json"></code-sample-editor>

<code-sample-editor> uses bare module specifiers in its code, so you'll need a server that supports rewriting module specifiers with the Node module resolution algorithm, or a build tool like Rollup.

<code-sample-editor> also uses import.meta.url to load the worker scripts. note that Webpack does not support that currently.

Development

After cloning the repo:

npm install

# runs npm run watch and npm run serve at the same time
npm run dev

Open your browser to http://localhost:8081/demo/ to see the demo.

Project organization

The project is organized into multiple TypeScript projects, one for each browser/worker environment, and one shared project. They reference each other via TypeScript project references and are built together with the --build flag to tsc.