Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import createEmojiPlugin from "draft-js-emoji-plugin";
import createHashtagPlugin from "draft-js-hashtag-plugin";
import createLinkifyPlugin from "draft-js-linkify-plugin";
import createCounterPlugin from "draft-js-counter-plugin";
import classNames from "classnames";
import { scaledThumbnailUrlFor } from "../utils/media-url-utils";
import { Modifier, EditorState } from "draft-js";
import "draft-js-emoji-plugin/lib/plugin.css";
import "draft-js-hashtag-plugin/lib/plugin.css";
import "draft-js-linkify-plugin/lib/plugin.css";
import "draft-js-counter-plugin/lib/plugin.css";
const emojiPlugin = createEmojiPlugin();
const hashtagPlugin = createHashtagPlugin();
const linkifyPlugin = createLinkifyPlugin();
const counterPlugin = createCounterPlugin();
// Taken from draft-js-emoji
const addEmoji = (emoji, editorState) => {
const contentState = editorState.getCurrentContent();
const contentStateWithEntity = contentState.createEntity("emoji", "IMMUTABLE", { emojiUnicode: emoji });
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
const currentSelectionState = editorState.getSelection();
let emojiAddedContent;
let emojiEndPos = 0;
let blockSize = 0;
// in case text is selected it is removed and then the emoji is added
const afterRemovalContentState = Modifier.removeRange(contentState, currentSelectionState, "backward");
// deciding on the position to insert emoji
// It is important to import the Editor which accepts plugins.
import Editor from 'draft-js-plugins-editor'; // eslint-disable-line import/no-unresolved
import createCounterPlugin from 'draft-js-counter-plugin'; // eslint-disable-line import/no-unresolved
import React from 'react';
// Creates an Instance. At this step, a configuration object can be passed in
// as an argument.
const counterPlugin = createCounterPlugin();
// Extract a counter from the plugin.
const { CharCounter } = counterPlugin;
// The Editor accepts an array of plugins. In this case, only the counterPlugin is
// passed in, although it is possible to pass in multiple plugins.
// The Counter is placed after the Editor.
const MyEditor = ({ editorState, onChange }) => (
<div>
</div>
import React, { Component } from 'react';
import Editor, { createEditorStateWithText } from 'draft-js-plugins-editor';
import createCounterPlugin from 'draft-js-counter-plugin';
import editorStyles from './editorStyles.css';
const counterPlugin = createCounterPlugin();
const { CharCounter, WordCounter, LineCounter, CustomCounter } = counterPlugin;
const plugins = [counterPlugin];
const text = `This editor has counters below!
Try typing here and watch the numbers go up. 🙌
Note that the color changes when you pass one of the following limits:
- 200 characters
- 30 words
- 10 lines
`;
export default class SimpleCounterEditor extends Component {
state = {
editorState: createEditorStateWithText(text),
};
import React, { Component } from 'react'
import Editor, { createEditorStateWithText } from 'draft-js-plugins-editor'
import createCounterPlugin from 'draft-js-counter-plugin'
import 'draft-js-counter-plugin/lib/plugin.css'
const counterPlugin = createCounterPlugin()
/*
import styles from './Counter.css'
const theme = {
counter: styles.counter,
counterOverLimit: styles.counterOverLimit
}
const counterPlugin = createCounterPlugin({ theme })
*/
const { CharCounter, WordCounter, LineCounter, CustomCounter } = counterPlugin
const plugins = [counterPlugin]
const text = `This editor has counters below!
Try typing here and watch the numbers go up. 🙌
Note that the color changes when you pass one of the following limits:
import React, { Component } from 'react';
import Editor, { createEditorStateWithText } from 'draft-js-plugins-editor';
import createCounterPlugin from 'draft-js-counter-plugin';
import editorStyles from './editorStyles.css';
import counterStyles from './counterStyles.css';
const theme = {
counter: counterStyles.counter,
counterOverLimit: counterStyles.counterOverLimit,
};
const counterPlugin = createCounterPlugin({ theme });
const { CharCounter, WordCounter, LineCounter, CustomCounter } = counterPlugin;
const plugins = [counterPlugin];
const text = `This editor has counters below!
Try typing here and watch the numbers go up. 🙌
Note that the color changes when you pass one of the following limits:
- 200 characters
- 30 words
- 10 lines
`;
export default class CustomCounterEditor extends Component {
state = {
editorState: createEditorStateWithText(text),
};
constructor(props: Props): void {
super(props);
const modalPlugin = createModalPlugin();
const { closeModal, setModalContent, Modal } = modalPlugin;
const counterPlugin = createCounterPlugin();
const modalConfig = {
closeModal: closeModal,
setModalContent: setModalContent
};
const linkPlugin = createLinkPlugin({
...modalConfig
});
const { LinkButton } = linkPlugin;
const components = {};
const toolbarStructure = [BoldButton, ItalicButton, UnorderedListButton, ToolbarSeparator, LinkButton, ToolbarSeparator];
const plugins = [counterPlugin, linkPlugin];
if (props.withAttachmentButton) {
const attachmentPlugin = createAttachmentPlugin({
...modalConfig
});