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

@pahans/react-htmltree

v0.8.1

Published

React component for HTML structures based on a string, react component or DOM node

Downloads

8

Readme

js-standard-style

React HTMLTree

TreeView for HTML/XML structures

The motivation for this component was the lack of a standalone TreeView for HTML documents, which can be easily integrated. Existing solutions are often tightly coupled into specific projects or don't provide necessary customizations options. While its original is based on the TreeView implementation of react-devtools, additional improvements regarding performance and usability were done.

Checkout the example in your browser.

Chrome DevTools | Firefox DevTools - Light | Firefox DevTools - Dark :--------------:|:-------------------------:|:----------------------: Chrome DevTools Theme|Firefox DevTools Theme - Light|Firefox DevTools Theme - Dark

Features

  • standalone react module with inline style definitions
  • default themes include 'Chrome' and 'Firefox' visuals
  • mimics common devtools behavior (like history or uncollapse all descendants)
  • supports universal rendering through difference source types
  • keeps synchronized with the DOM if an HTML element is referenced

Use Cases

  • document viewer
  • devtools extension
  • visual debugging
  • interactive markup

How To use

import HTMLTree from 'react-htmltree'

<HTMLTree source={document.documentElement}/>

source: Text | React Component | HTMLElement

Handle Events

<HTMLElement source={document.documentElement} onSelect={handleSelect}/>

// others events include: 'hover', 'expand' and 'unfocus'
function handleSelect (element, component) {
  console.log(element)
}

Use custom renderer

<HTMLElement source={'<ul><li>1</li><li>2</li></ul>'} customRender={customRender}/>

// create wrapper around the matched components
function customRender (decorate, node) {
  return decorate(function (Component) {
    if (node.name === 'script') {
      return (
        <div style={{ backgroundColor: 'red' }}>
          <Component {...Component.props}/>
        </div>  
      )
    }
  })
}

Further examples can be found here.

Development

To build your own version run npm run dev for development (incl. watch) or npm run build for production (minified).

TODO

  • extend example page with style generator
  • checkout memory issue after theme change
  • only render elements in the current viewport (reuse DOM nodes)
  • allow object declaration for a styling a custom theme regarding freestyle
  • prevent duplicate inline style imports for the select theme
  • extend documentation (react-docgen)
  • add tests for the component using (enzyme)
  • checkout the original styles of the developer tools (chrome ? firefox ?)
  • support syntax highlighting for inline scripts / style elements
  • check rendering using web worker for more efficient updating (diff checks) ~ react-worker-dom / #3092
  • adapt further features from browser devtools:
    • wrap dotted border around each specific (firefox)
    • tags with no content are less saturated (firefox)