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-area51

v0.1.0

Published

Area51 allows mysterious alien content (from a CMS) to take control of your React app.

Downloads

1

Readme

Area51

Area51 allows mysterious alien content to take control of your React app. :alien:

This is Alpha software. Subject to frequent change. Not yet officially supported.:warning:

react-area51 enables content authors to manage the actual structure and layout of a React app, not just the content items. It was created to re-empower non-developers to create and edit React-based websites and other digital experiences. Area51 connects the modern component-architecture of React, with the component concept of CMS page editors. It does not include an editing tool itself, but provides the infrastructure an editing UI can plug into.

Capabilities

  • Use any React component without modification. They recieve all CMS-managed content passed in as props.
  • Handles injecting 'EditorHints' into the DOM to support the editing UI of the CMS.
  • Supports managing nested components.
  • Supports managing a tree of 'pages'.

Note: This package is 'CMS agnostic', you can use it to hook up your own editing UI and content structures. Alternatively, use one of the CMS-specific packages based on it.

Screenshot of React Aliens Demo Project being edited in a CMS. Area51 Demo Project in Magnolia

How Area51 works

react-area51 provides an Area React component that is dynamically populated with React components and content based on a JSON configuration, typically from a CMS REST endpoint. The configuration stores both an ordered list of React components, and their content, which will be passed as props to the instantiated React components. Because an instantiated React component may itself contain an area, the configuration can also be a tree, instead of a list. In an edit mode, Area51 adds markup or data attributes to the Area component and its child components to allow an external tool to add an editing UI to interact with the configuration.

How to Use Area51 in your React project

Find the Area51 library for your CMS or editor.

(If one does not exist you will need to create one. See the following section.)

Setup

  • Install the Area51 npm package for your CMS. For example magnolia-react-area51. It provides Area React component.
  • Place Area components in your existing React app wherever you want externally managed components. Example
  • Configure these props on your Area components:
    • cmsAreaName: The name of the corresponding area in your CMS.
    • parentPath: The full path to the CMS content node that will hold the areas contents. (Typically dynamically generated.)
    • parentTemplateId: The ID of the template of the node hosting this area in your CMS.
  • Create a mapping configuration file so Area51 can map the template ID's from your CMS, with the React components to be instantiated. Example
  • Configure the environment variables to point to your CMS instance. Example
  • Modify the package.json clean and copy npm scripts to deploy to your CMS location.

Tips

  • Ensure that the CMS page template that hosts the React app has a DIV with the proper id (Usually "app" or "app-root".) (It has to match whatever is in your react app public/index.html file.
  • You may need to adjust the Router in your React app to accept '.html' since this will probably be appended to the URL when running in the CMS.

Creating an Area51 for your CMS or editing UI

  • Install the react-area51 npm package.
  • Implement two classes specificaly for your CMS or editing UI:'ContextService' and 'EditorHintHelper'.
  • Export an index.js file (Reference implementation ) that wraps the basic Area component with an HOC which provides your custom ContextService and EditorHintHelper.
  • Enjoy!

ContextService A service that gives Area51 all it needs to operate on the CMS content that is stored in the Area51Context state. Reference implementation

  • getAreaDefinitionFromTemplate - Return the area definition from a specific template.
  • getAreaComponents - Return the components (actual content) of an area.
  • getPage - Return the actual content of a page.
  • getTemplate - Return the template definition.
  • inEditionMode - Return whether the page is in edition mode.

EditorHintHelper Generate the markup required for the Page Editing UI. A CMS will usually include specific markup in the DOM so that it's Page Editor knows where to inject editing UI elements, and how they should be configured. Reference implementation

  • addComponentHint - Add editor hints to the DOM for a component.
  • addAreaHint - Add editor hints to the DOM for an area.

Technical Details :triangular_ruler:

The React application loads the JSON with the content and stores this in a React Context Area51Context.

The Area components instantiate React components using React.createComponent(), and wrap each component with an HOC withArea51 which grabs the appropriate content from the Area51Context and passes it directly as props to the component.

withArea51 also provides the 'EditorHints' which are included in the DOM to allow the components to be managed in the CMS.

Area51 Architectural Diagram

Technical Notes

An environment variable REACT_APP_LOG_LEVEL can be set to 0 or 1 to control if messages are logged to the console.

License

MIT

Contributors

  • Adrien Manzoni, Magnolia
  • Christopher Zimmermann, Magnolia
  • Your name here! :grinning: