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

editorjs-viewer-native

v1.0.1

Published

A React Native viewer for JSON created by EditorJs

Downloads

423

Readme

npm version npm downloads

About

This lib provide a component to render in a React Native a JSON generated by Editor.js!

Installation

Version 1.0.0 is now available!

npm i editorjs-viewer-native

or

yarn add editorjs-viewer-native

Current support for editorJs's plugins:

See the update plans

Usage

Create a component using function createEditorJsViewer.

import { ScrollView } from 'react-native';
import { createEditorJsViewer } from "editorjs-viewer-native";

import dataFromEditorJs from "./data.json";

const EditorJsViewerNative = createEditorJsViewer();

export default function App() {
  return (
    <ScrollView>
      <EditorJsViewerNative data={dataFromEditorJs} />
    </ScrollView>
  );
}

Custom component for supported plugins

If you want to use your custom component to render any supported plugin block, you can define a Component in createEditorJsViewer config object.

import { ScrollView, Text } from 'react-native';
import { createEditorJsViewer, IHeaderProps } from "editorjs-viewer-native";
import dataFromEditorJs from "./data.json";

const MyHeader = ({ data }: IHeaderProps) => {
  return <Text>{data.text}</Text>
}

const EditorJsViewerNative = createEditorJsViewer({
  tools: {          // Updated to "tools" in v1 (before was toolsParser)
    header: {
      Component: MyHeader // Updated to "Component" in v1 (before was CustomComponent)
    }
  }
})

export default function App() {
  return (
    <ScrollView>
      <EditorJsViewerNative data={dataFromEditorJs} />
    </ScrollView>
  );
}

Now the component MyHeader will render all data of type header.

Support for custom blocks

If you want to render a custom block type, you can define a customTools in createEditorJsViewer config object.

// outputData.json
{
  "blocks": [
    {
      "id": "customBlock_id2",
      "type" : "randomColeredText",
      "data" : {
        "text" : "The color of this text is generated randomic"
      }
    }
  ]
}
import { ScrollView, Text } from 'react-native';
import { createEditorJsViewer, IHeaderProps, IComponentBlockProps } from "editorjs-viewer-native";
import dataFromEditorJs from "./data.json";

interface IRandomColeredTextData {
  text: string;
}

// ! Any componente will receive "data" and "containerStyle"
// "data" contain the data of block
// "containerStyle" is a simple style to prevent margim top on first element or margimBottom on last component
const RandomColeredTextBlock = ({ block, containerStyle }: IComponentBlockProps<IRandomColeredTextData>) => {
  const randomColor = `#${Math.floor(Math.random()*16777215).toString(16)}`;
  return (
    <Text style={[{ color: randomColor }, containerStyle]}>{block.data.text}</Text>
  );
};

const EditorJsViewerNative = createEditorJsViewer({
  customTools: {
    randomColeredText: { // Name of your custom block type
      Component: RandomColeredTextBlock
    }
  }
})

export default function App() {
  return (
    <ScrollView>
      <EditorJsViewerNative data={dataFromEditorJs} />
    </ScrollView>
  );
}

Now the component MyHeader will render all data of type header.

Fallback for unsupported block types

If you want to show a message for unsupported blocks (good for test, bad for production) set showBlockFallback as true inside createEditorJsViewer config object.

const EditorJsViewerNative = createEditorJsViewer({
  showBlockFallback: true // Update to "showBlockFallback" (before was unknownBlockFallback)
})

Updates plans

Support for:

Open source

Feel free to clone/fork this project!