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

slate-react-serializer

v1.0.2

Published

Made with create-react-library

Downloads

14

Readme

slate-react-serializer

Made with create-react-library

NPM JavaScript Style Guide

Install

npm install --save slate-react-serializer

Usage

import React, { Component } from 'react'

import getSerializer from 'slate-react-serializer';

const serializer = getSerializer();

class Example extends Component {
  render() {
    return serializer(this.props.slateValue)
  }
}

By default, will serialize:

  • div
  • quote
  • 'block-quote'
  • paragraph
  • link
  • 'bulleted-list'
  • 'heading-one'
  • 'heading-two'
  • 'heading-three'
  • 'heading-four'
  • 'heading-five'
  • 'heading-six'
  • 'list-item'
  • 'check-list-item'
  • 'numbered-list'
  • q
  • p
  • a
  • ul
  • h1
  • h2
  • h3
  • h4
  • h5
  • h6
  • li
  • ol
  • bold
  • code
  • italic
  • underline

Add custom serializer

const Embeds = () => {
  const value = [{"type":"paragraph","children":[{"text":"In addition to simple image nodes, you can actually create complex embedded nodes. For example, this one contains an input element that lets you change the video being rendered!"}]},{"type":"video","url":"https://player.vimeo.com/video/26689853","children":[{"text":""}]},{"type":"paragraph","children":[{"text":"Try it out! This editor is built to handle Vimeo embeds, but you could handle any type."}]}]
  const customTypes = {
    video: ({ url }) => (
      <div style={{ padding: '50% 0px 0px', position: 'relative' }}>
        <iframe src={url} style={{ position: 'absolute', top: '0px', left: '0px', width: '100%', height: '100%' }} />
      </div>
    )
  }
  const serializer = getSerializer({ customTypes });

  return serializer(value);
}

Override default serializer

const OverrideDefaults = () => {
  const value = [{"type":"paragraph","children":[{"text":"This is editable "},{"text":"rich","bold":true},{"text":" text, "},{"text":"much","italic":true},{"text":" better than a "},{"text":"<textarea>","code":true},{"text":"!"}]},{"type":"paragraph","children":[{"text":"Since it's rich text, you can do things like turn a selection of text "},{"text":"bold","bold":true},{"text":", or add a semantically rendered link in the middle of the page, like this:"}]},{"type":"link","url":"https://en.wikipedia.org/wiki/Hypertext","children":[{"text":"Override link html"}]},{"type":"paragraph","children":[{"text":"Try it out for yourself!"}]}];
  const customTypes = {
    bold: ({ children }) => <span style={{ fontWeight: 700 }}>{children}</span>,
    link: ({ children }) => <button>{children}</button>
  }
  const serializer = getSerializer({ customTypes });

  return serializer(value);
}

Output html string instead of react code

const ReturnHTML = () => {
  const value = [{"type":"paragraph","children":[{"text":"This is editable "},{"text":"rich","bold":true},{"text":" text, "},{"text":"much","italic":true},{"text":" better than a "},{"text":"<textarea>","code":true},{"text":"!"}]},{"type":"paragraph","children":[{"text":"Since it's rich text, you can do things like turn a selection of text "},{"text":"bold","bold":true},{"text":", or add a semantically rendered block quote in the middle of the page, like this:"}]},{"type":"block-quote","children":[{"text":"A wise quote."}]},{"type":"paragraph","children":[{"text":"Try it out for yourself!"}]}];

  const serializer = getSerializer({ returnHTML: true, });

  return serializer(value);
}

Disable defaults

const Disables = () => {
  const value = [{"type":"paragraph","children":[{"text":"This is editable "},{"text":"rich","bold":true},{"text":" text, "},{"text":"much","italic":true},{"text":" better than a "},{"text":"<textarea>","code":true},{"text":"!"}]},{"type":"paragraph","children":[{"text":"Since it's rich text, you can do things like turn a selection of text "},{"text":"bold","bold":true},{"text":", or add a semantically rendered block quote in the middle of the page, like this:"}]},{"type":"block-quote","children":[{"text":"A wise quote."}]},{"type":"paragraph","children":[{"text":"Try it out for yourself!"}]}];

  const serializer = getSerializer({ disables: ['bold', 'block-quote']});

  return serializer(value);
}

Add a markdown serializer

const Markdown = () => {
  const value = [{"type":"paragraph","children":[{"text":"Slate is flexible enough to add **decorations** that can format text based on its content. For example, this editor has **Markdown** preview decorations on it, to make it _dead_ simple to make an editor with built-in Markdown previewing."}]},{"type":"paragraph","children":[{"text":"## Try it out!"}]},{"type":"paragraph","children":[{"text":"Try it out for yourself!"}]}]

  const markDownSerializer = (text) => processText(text) // PROCESS MARKDOWN TEXT;

  const serializer = getSerializer({ markDownSerializer });

  return serializer(value);
}

License

MIT © jeremygottfried