GithubHelp home page GithubHelp logo

draft-js-plugins / draft-js-plugins Goto Github PK

View Code? Open in Web Editor NEW
4.1K 4.1K 1.0K 24.7 MB

React Plugin Architecture for Draft.js including Slack-Like Emojis, FB-Like Mentions and Stickers

Home Page: https://www.draft-js-plugins.com/

License: MIT License

JavaScript 27.46% Shell 0.06% CSS 7.79% HTML 0.01% TypeScript 64.68%
draft-js draft-js-plugins hashtags mentions react stickers

draft-js-plugins's Introduction

DraftJS Plugins

Draft JS Plugins Logo

High quality plugins with great UX on top of DraftJS.

Build Status

Available Plugins (incl. Docs)

Built by the community

Live Example & Documentation

Checkout the website!

Usage

First, install the editor with npm:

$ npm install @draft-js-plugins/editor --save

Then import the editor somewhere in your code and you're ready to go!

import Editor from '@draft-js-plugins/editor';

Documentation

@draft-js-plugins/editor

Editor

An editor component accepting plugins. see source

Props Description Required
editorState see here *
onChange see here *
plugins an array of plugins
decorators an array of custom decorators
defaultKeyBindings bool
defaultBlockRenderMap bool
all other props accepted by the DraftJS Editor except decorator see here

Usage:

import React, { Component } from 'react';
import Editor from '@draft-js-plugins/editor';
import createHashtagPlugin from '@draft-js-plugins/hashtag';
import createLinkifyPlugin from '@draft-js-plugins/linkify';
import { EditorState } from 'draft-js';

const hashtagPlugin = createHashtagPlugin();
const linkifyPlugin = createLinkifyPlugin();

const plugins = [linkifyPlugin, hashtagPlugin];

export default class UnicornEditor extends Component {
  state = {
    editorState: EditorState.createEmpty(),
  };

  onChange = editorState => {
    this.setState({
      editorState,
    });
  };

  render() {
    return (
      <Editor
        editorState={this.state.editorState}
        onChange={this.onChange}
        plugins={plugins}
      />
    );
  }
}

How to write a Plugin

Feel free to copy any of the existing plugins as a starting point.In this repository you can also find a Guide on how to create a plugin, including a description of the supported features. In addition you can contact @nikgraf directly in case you need help or simply open a Github Issue!

Discussion and Support

Join the channel #draft-js-plugins after signing into the DraftJS Slack organization or check out our collection of frequently asked questions here: FAQ.

Development

Check out our Contribution Guide.

Learn about why Draft.js and how to use DraftJS Plugins

In this talk Nik Graf explained the ContentState structure of a Draft.js Editor as well as explained how to use plugins.

License

MIT

draft-js-plugins's People

Contributors

adrianmcli avatar amannn avatar dependabot-preview[bot] avatar dependabot[bot] avatar dimaslz avatar djkirby avatar freedomlang avatar fxone avatar hcompullreq avatar jl- avatar jonrossmacmillan avatar jpuri avatar juliankrispel avatar khkmzynv avatar max-winderbaum avatar mxstbr avatar mzbac avatar nihaux avatar nikgraf avatar nil1511 avatar psbrandt avatar sibelius avatar simsim0709 avatar steven-qi avatar sugarshin avatar svnm avatar tarjei avatar thmsobrmlr avatar trysound avatar williamli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

draft-js-plugins's Issues

Plugin System for Draft-JS

While I believe draft-js would benefit from a plugin system I think this would be quite a heavy change they do not want to focus on right now.

I was thinking if we could create a higher order component or a abstraction on top of draft-js to allow a plugin system.

Options for mention identifier

I think the work you're doing is great! I really hope that the plugin system you're building can become the standard way of building plugins for draftjs.

The application I'm working on is persisting data entered through Draftjs as HTML The way the mention plugin is currently working, it's removing the '@' from the content, meaning that when the content is rendered as html, there's no way of recognizing the string as a mention afterwards.

A quick fix for me would be to persist the '@' character either visible or invisibly so that I have a way of knowing that the given string is a mention

History Plugin

The editor state contains a list of the operations. Would be nice to render this a history. Probably something similar to what Google Docs History, Photoshop History or Redux Devtools.

Add an example for @ mentions including an autocomplete

I think for a first example a static list of users to auto complete should be good enough.

Since names contain of multiple parts making them segmented sounds like a good idea. That's the Facebook behaviour where it autocompletes to the full-name, but people are still able to remove parts without removing the entity.

In here you have basic implementation of @ mentions. Extending it with a autocomplete will be tricky, but definitly doable. https://github.com/facebook/draft-js/blob/master/examples/tweet/tweet.html

Add StickerSet component

To be honest I have no idea what a good sticker set component should be like, but something nicer than just looping over the data would be cool.

Allow to update the plugins and set new decorators

This issue needs to be fixed first:

hellendag [12:06 PM] 
:simple_smile:

[12:07] 
The only thing to be careful of with setting a new decorator right now is that `beforeInput` allows native character insertion, so that's causing some problems

[12:07] 
I need to come up with a good solution for that

[12:07] 
So right now, if you set a new decorator in `onChange` and the new state is coming from a `beforeInput`, there can be some rendering bugs

nikgraf [12:08 PM] 
I think I had this issue

hellendag [12:08 PM] 
Double character rendering, mostly

nikgraf [12:08 PM] 
I type in character `a`and it results in 2 a `aa`

[12:08] 
exactly

hellendag [12:08 PM] 
Yeah

[12:08] 
So right now, the way around that is to propagate the new state with a `setTimeout`, to allow the native insertion

[12:08] 
It works, but it's not pretty

[12:09] 
And I need to come up with something better

Stickers [improvements]

  • add mutiple sets & categories to the selector
  • comply with aria recommendations
  • proper pseudoclass styles

Performance Improvements

For some reason the editor is way slower than what you can see on the original pages. Investigate the bottle neck & fix it.

First ideas:

  • onChange is heavy
  • componentWillReceiveProperties is slowing down
  • when plugins are initialised we can store which functions actually should be cold and don't have to loop over every plugin

CreateFromText doesn't take plugins as a parameter

One problem i'm running into with the mentionsPlugin is that if I initialize the editor with content - that contains a @ character - it will not trigger the mentions plugin at all. Until I've deleted the character, committed the state and reinitializes it without it.

I figured that was the reason for the built in createFromText function - but it doesn't seem to do anything else than wrap the native functions of DraftJs (and doesn't even take the plugins array as specified in the documentation)

I know the documentation is far from done - I just wanted to know a bit about the thinking behind it :)

Launch/Release Plan

  • split repos into main Editor & a repo for each plugin in an Github organisation. Take the whole repo and then remove things from there. This way the existing contributors are preserved 🙌
  • add tool to convert into pure html/text + immutable data structure
  • add a logo (maybe a piece of paper in a circle?)
  • add fancy header
  • add logo to readme
  • animate all sorts of interactions on the page (see how Stripe is investing in the details)
  • add Google Analystics to the page
  • get 1-3 quotes from DraftJS core contributors (He won't do it at the moment)
  • add a mailing list sign up (Mailchimp?)
  • Write Medium Post on "Why DraftJS will have a huge impact on communication tools in 2016"
    • It is game changer for saving data, because sanitising data is hard. The Data model can easily be converted if necessary.
    • DraftJS can become a platform (this plugin system is a first attempt)
  • Tweet: In 2016 we will see an enhanced experience in web communication tools #DraftJS #notSoBoldPrediction
  • add “Try it out button”
  • add a guide on what's possible on the "try it out" section
  • add comments all over the place
  • add og tags so it looks fancy (make sure twitter & facebook preview are fine)
  • add guide how to write a Plugin
  • make it look nice (at least decent) on mobile to make (soo many people check stuff on mobile)
  • add section with future plans (website & readme)
  • add social sharing buttons
  • mention react & draftjs and link to them (thx to Skander for the suggestion)
  • Works on: webicon iosicon androidicon ereadericon (thx to Skander for the suggestion)
  • add thx to stripe section at the bottom
  • add buttons for npm version & license
  • Post on ProductHunt
  • Post on HackerNews
  • Post on Reddit
  • Ping relevant people on Twitter

StickerSelector improvements

  • prevent scrolling the page inside the popover
  • add subtle white gradient/shadow at the bottom to indicate people can scroll

[Mentions] Improvements

  • let the user decide between immutable, segmented or mutable
  • animate the popover
  • improve colours
  • use handle & name
  • remote example
  • themed example with a static list below the editor
  • proper naming
  • marketing for mobile optimization (test on mobile device)
  • fix aria tag issue for editor
  • fix scrolling issue
  • option to keep @
  • add initialize callback to editor
  • update homepage example
  • properly align the box
  • make it mobile ready (check touch)
  • use flexbox
  • switch to non immutable classname list
  • allow to take a promise for mentions data as well
  • make sure mentions popover stay at the same position
  • custom key handling for dropdown (@nikgraf working on it)
  • make sure in case no link exists it does not become an Anchor tag
  • add profilepics/icons
  • only show/use images if all mentions have images
  • use unicorn name & unicorn profile pictures for the the dataset
  • use an algorithm to filter for name - see ComboBox algorithm of Belle
  • don't add a space at the end if the mention is somewhere in between
  • when you type too far ahead so no result shows up and you hit backspace the dropdown should appear again (only happens when somewhere in between text)
  • allow to provide an extended config
  • close the dropdown when clicking somewhere outside of it and loosing focus
  • close dropdown when the selection moves away
  • fix onclick on the mention option (doesn't work right now)
  • add active state for the mention option

Improve hashtag regex

Nik: what’s wrong with this regex?
Isacc: It's a weak regex for i18n hashtag handling, IIRC

Let's check how to improve it

Fancy animations for the plugins

  • focused option in the mentions list could be a quick fadeIn/fadeOut of the background
  • adding mentions should be smooth animation after the replace
  • fade in for stickers
  • emoji gets same animations as mentions

Plugin Configuration

Mention Plugin

{
  mentions: List([Map({
    link: String,
    avatarUrl: String  
  })]),
  theme: {
    search: Map(),
    mention: Map(),
   },
}

Hashtag Plugin

{
   theme: {
      hashtag: Map(),
   }
}

Undo Plugin

{
  theme: {
    undoButton: Map(),
    redoButton: Map(),
  }
}

Link Plugin

{
   theme: {
      link: Map(),
   }
}

stickerPlugin

{
   theme: {
     sticker: Map(),
     stickerSelect: Map(),
   }
}

emojiPlugin

{
   emojis: List([Map(
     url: String,
     name: String,
     key: String,
     unicodeCharacter: String, // (replaced with image, should only show image if it is in the list of emojis)
   )]),
   theme: {
     emoji: Map(),
     emojiSelect: Map(),
   }
}

Emoji Plugin

I quite like Slack's implementation where you can start with a : and type the name like :heart: which also autocompletes. Pasting in real emojis also works.

Documentation Pages

  • add social bar to the bottom of every page before the footer - I have added this section to bottom of all pages. May be options should better be aligned in a single line - plz suggest @nikgraf.
  • add a section "Team" to the homepage with a picture & links (both twitter) to https://twitter.com/jyopur https://twitter.com/nikgraf https://twitter.com/mxstbr https://twitter.com/juliandoesstuff
  • add section "Discussion and Support" to bottom of the homepage & readme with
    Join the channel #plugin-editor after signing into the DraftJS Slack organisation!
  • allow Code component to be collapsed or expanded. the initial state can be passed in via props, but it should be uncontrolled - this is done but atm, code clocks expand / collapse on mouse clicks this can be improved @nikgraf suggestions plz.

Fix focus issue

When clicking somewhere in the editor it should mimic the native behaviour and set the cursor at the end.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.