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

react-designer-core

v1.4.1

Published

React-designer-core is a set of core components for easy content creation.

Downloads

40

Readme

react-designer-core

React-designer-core is a set of core components for react-designer. This is WYSIWYG editor for easy content creation (legal contracts, business forms, marketing leaflets, technical guides, visual reports, rich dashboards, tutorials and other content, etc.).

Live demos

Main goals

  • it is for developers - to use it in your own solutions with your own widgets (components)
  • it is based on simple principals
    • minimal JSON definition - PTT - maps directly to React components
    • good performance even for big documents - due to usage of immutable structure using freezer-js
    • simple extensible by custom components or frameworks (react-bootstrap, material-design, your company made widgets, etc.)
  • offers standard design components (Workplace, Container, Box, ObjectBrowser) and features
    • layouting - moving positions, resizing, moving up/down in component hieararchy, copying, deleting, etc.
    • component editing - property editors, inline editing - using draftjs, streching, rotating, transforming transhand,etc.
    • workplace - selecting, undo/redo, previewing, import/export, etc.

It comes with core components typical for WYSIWYG designers

  • Workplace - main working area for drawing documents
  • ObjectTree - logical component tree - enables to search and move components between nodes

Document definition is done in JSON - uses PTT

  • document definition - simple JSON - Page Transform Tree (PTT) - it is framework agnostic definition
  • document rendering - visual component tree - React virtual DOM - rendering to DOM so that it maps each component (terminal node) from logical tree to react component and its properties

Document definition - PTT

The PPT format is framework agnostic document description. It enables to dynamically render pages in different sizes (A4,A3,Letter,...),in various formats (html,pdf,...) and for various visual media (screen, papers).

It is a simple component tree that consists of these two nodes

  • containers - nodes that are containers for other components - visual and logical grouping of parts of document (sections, containers,grids, rows, cells, panels, etc. )
  • boxes - terminal nodes (leaf) that are visible components - (components, boxes, widgets) - renders to document (typically by simple mapings to props of component)

There is an minimal 'Hello world' example. The PTT consists of one container and one box with TextBox element.

{
 "name": "Hello World Example",
 "elementName": "PTTv1",
 "containers": [
    {
     "name": "My first container",
     "elementName": "Container",
     "style": { "top": 0, "left": 0, "height": 200, "width": 740, "position": "relative" },
     "boxes": [{
        "name": "My first text",
        "elementName": "TextContent",
        "style": { "top": 0, "left": 0 },
        "props":{
             "content": "Hello world"
            }
        }]
    }]
}

See the full PTT specification.

Document rendering - visual component tree - PTT rendering in react

To render react components specifies in react is really simple

    render:{
       {this.props.boxes.map(function (box, i) {
                var component = React.createElement(widget,box, box.content!== undefined?React.DOM.span(null, box.content):undefined);
                return (
                       <div style={box.style}>
                            {component}
                       </div>
                       );
       }, this)}
    }

Demo & Examples

To build the examples locally, run:

npm install
gulp dev

Then open localhost:8000 in a browser.

Installation

The easiest way to use this component is to install it from NPM and include it in your own React build process (using Browserify, Webpack, etc).

You can also use the standalone build by including dist/react-designer-core.js in your page. If you use this, make sure you have already included React, and it is available as a global variable.

npm install react-designer-core --save

Usage

import {Workplace,ObjectBrowser} from 'react-designer-core';


import React from 'react';
import Freezer from 'freezer-js';
import Designer from './Designer';

// Create a Freezer store
var freezer  = new Freezer({
  schema: {
    elementName: 'ObjectSchema',
    name: 'New Document',
    containers: []
  }
})

export default class AppContainer extends React.Component {

   componentDidMount() {
     var me = this;

     // 2. Your app get re-rendered on any state change
     freezer.on('update', function () {
       me.forceUpdate()
     });
   }

   render() {
     // 1. Your app receives the state
     var state = freezer.get();
     return <Designer state={ state } />;
   }
 }

import React from 'react';
import {Workplace,ObjectBrowser} from 'react-designer-core';

import Widgets from './Widgets';
import WidgetRenderer from './WidgetRenderer';


export default class Designer extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      current: {
        node: props.state.schema
      },
      snapGrid: [10, 10]
    }
  }

  currentChanged(currentNode, path) {
    if (currentNode === undefined) return;
  
    this.setState({
        current: {
          node: currentNode,
          path: path === undefined ? this.state.current && this.state.current.path : path
        }
      }
    );
  }
  
 render() {
    var schema = this.props.state.schema;
    return
     	<div className="index">
            <Workplace schema={schema} current={this.state.current}
                       currentChanged={this.currentChanged.bind(this)} widgets={Widgets}
                       widgetRenderer={WidgetRenderer} snapGrid={this.state.snapGrid}/>
            <ObjectBrowser rootNode={schema} current={this.state.current}
                       currentChanged={this.currentChanged.bind(this)}/>
      	</div>
 }
}

See the example folder to see more features.

License

MIT. Copyright (c) 2015 Roman Samec