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

@zhongbr/code-sandbox

v0.0.1

Published

Display JSX Code demos in your web pages easily.

Downloads

3

Readme

Code Sandbox

1. Install

React Component

npm install @zhongbr/code-sandbox
import ReactDom from 'react-dom';
import  CodeSandbox, { registerPlugins } from '@zhongbr/code-sandbox';
import { ReactPolyfill } from '@zhongbr/code-sandbox/es/plugins/react';
import { JsxPlugin } from '@zhongbr/code-sandbox/es/plugins/babel';

registerPlugins([
    new ReactPolyfill(),
    new JsxPlugin(),
]);

ReactDom.render(<CodeSandbox html="<h1>hello world</h1>" />, document.getElementById('root'));

webcomponent

es module

<script type="module">
  import {
    CodeSandbox,
    registerPlugins
  } from "https://cdn.jsdelivr.net/npm/@zhongbr/code-sandbox@latest/es/webcomponent.js";
  import { ReactPolyfill } from "https://cdn.jsdelivr.net/npm/@zhongbr/code-sandbox@latest/es/plugins/react/index.js";
  import { JsxPlugin, EsmToAmdPlugin } from "https://cdn.jsdelivr.net/npm/@zhongbr/code-sandbox@latest/es/plugins/babel/index.js";
  registerPlugins([new JsxPlugin(), new EsmToAmdPlugin(), new ReactPolyfill()]);
  if (!customElements.get("code-sandbox")) {
    customElements.define("code-sandbox", CodeSandbox);
  }
</script>
<code-sandbox
  html="<div id='root'>wait...🚀</div>"
/>

2. Base usage

Properties

The same properties between React component and Webcomponent .

| name | type | usage | |-------|--------|----------------------------------| | html | string | html code in sandbox | | css | string | css code in sandbox | | code | string | javascript code in sandbox | | index | string | entry javascript code in sandbox |

React Component properties

| name | type | usage | |-----------------|-------------------------------------------------|---------------------------------------------------------------------| | style | React.CSSProperties | inline styles for the iframe container | | class | string | css class name for the iframe container | | onLoadingModule | (moduleName: string, extraInfo: string) => void | event will be triggered when sandbox requiring module from internet | | onReady | () => void | event will be triggered when sandbox codes have executed finished . |

Web Component properties

| name | type | usage | |-----------|--------|---------------------------------------------| | style | string | inline style for sandbox iframe container | | className | string | css class name for sandbox iframe container |

Events

You can use addEventListener method of code-sandbox dom node to access the event.

  • loading-module: event will be triggered when sandbox requiring module from internet, you can get module informations from detail of the event object .
  • ready: event will be triggered when sandbox codes have executed finished .

3. Plugins

Internal plugins

Some internal plugins are provided in plugins directory of this package.

import { JsxPlugin } from '@zhongbr/code-sandbox/es/plugins/babel';
  • unpkg: UnpkgPlugin, use https://unpkg.com to load package not exists.
  • jsdelivr: JsdelivrPlugin, use https://jsdelivr.com to load package not exists.
  • react:
    • ReactPolyfill, this is a polyfill plugin to require react and react-dom package. If you want to require react packages in your demo code, you need to register this plugin, because there is no unpkg fields in react package.
  • babel: these plugins depend on @babel/standalone, so the bundle will be a little large.
    • JsxPlugin, you can register this plugin to execute JSX codes in sandbox.
    • EsmToAmdPlugin, you can register this plugin to use ESM import and export keywords in your sandbox.

Custom plugin lifecycles

  • resolveModuleUrl
  • require
  • beforeModuleGenerate