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

@mastir/react-diagram

v1.0.9

Published

Simple process flow and flow chart react diagram

Downloads

26

Readme

This project created as simple replacement for projectstorm/react-diagrams.

What is it

React diagram is a collection of base components to create flow chart or process flow.

Live demo

What is included

  • React components to implement base logic: Diagram, Node, Port, NodeDragZone
  • callbacks to handle business logic: Port.canConnect, Port.onConnect, NodeDragZone.onMove
  • base state handlers for: scroll, zoom, drag view, move nodes, connect ports.

How to use


    const engine = useMemo(() => {
        const engine = new EngineModel();
        engine.state.addStateHandler(new DefaultState());
        engine.state.addStateHandler(new CreateLinkState());
        engine.state.addStateHandler(new DragNodeState());
        engine.state.addStateHandler(new DragCanvasState());
        engine.state.actions.push(new ZoomHandler(engine));
        return engine;
    }, []);


    let node = {
        x: -85,
        y: -60,
        ports: [
          {name: 'First port!'},
          {name: 'Second port'},
        ]
    }
    
    let links = [];

    return <Diagram engine={engine} style={{minHeight:'100vh'}} links={links}>
        <Node model={node} position={[node.x,node.y]}>
              <NodeDragZone onMove={(x,y)=>{node.x=x;node.y=y}}>
                  <h1>Hello world!</h1>
              </NodeDragZone>
              {node.ports.map( (port,i) =>  <div key={i}>
                  <Port
                      key={i}
                      model={port}
                      canConnect={port2=>true}
                      onConnect={(port2,link) => {console.log('connect', port, port2, link); links.push(link)}}
                  >
                      <div style={{background:'#00F',width:16,height:16,display:'inline-block'}}/>
                  </Port>
                  {port.name}
              </div>)}
        </Node>
    </Diagram>;

Components

User defined types

TNode, TPort, TLink - unique string or any object representing element ( you should avoid object recreation or duplication )

Diagram

Root component

| prop | type | description | |--------------|------------------|------------------------------------------------------------------------------------------------------| | engine* | EngineModel | Main diagram container | | links* | TLink[] | List of all links to display | | createLink | (TPort)=>TLink | TLink factory | | getLinkStyle | (TLink) => style | default {color:'#FFF', width: 2, curviness: 50} | | linksLayer | React.Element | You can pass LinksLayer state handler wrap component (to avoid whole diagram redraw on link updates) |

Node

Container for any element placed in Diagram

| prop | type | description | |-----------|-----------------|----------------------------------------| | model* | TNode | any object represented by this element | | position* | [number,number] | node position x axis | | key | string | required for all nodes, its recomended to use any generated id|

Port

Container for connectors in Node

| prop | type | description | |--------|-------|----------------------------------------| | model* | TPort | any object represented by this element |

NodeDragZone

| prop | type | description | |--------|-------------|--------------------------------| | onMove | (x,y)=>void | callback for node moved action |

LinksLayer

react component to render links in svg

EngineModel

This is core container of the diagram. Engine contains 3 services: canvas, state, links

CanvasModel

Contain information about currently rendered elements and provide methods to work with coordinates and elements

StateMachineModel

Event processing service, active state handler can trigger state transitions. All of the action logic (zoom, drag canvas, move node, create link) realised in state handlers and can be extended and customized.

LinkListModel

Contain information about rendered TLink[] models and methods to redraw them