How to use the draftjs-filters.filterEditorState function in draftjs-filters

To help you get started, we’ve selected a few draftjs-filters examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ampproject / amp-wp / assets / src / edit-story / elements / text / util.js View on Github external
export function getFilteredState( editorState, oldEditorState ) {
	const shouldFilterPaste =
		oldEditorState.getCurrentContent() !== editorState.getCurrentContent() &&
		editorState.getLastChangeType() === 'insert-fragment';

	if ( ! shouldFilterPaste ) {
		return editorState;
	}

	return filterEditorState(
		{
			blocks: [],
			styles: [ 'BOLD', 'ITALIC', 'UNDERLINE' ],
			entities: [],
			maxNesting: 1,
			whitespacedCharacters: [],
		},
		editorState,
	);
}
github plone / volto / src / components / manage / Blocks / Text / Edit.jsx View on Github external
onChange(editorState) {
    const shouldFilterPaste =
      editorState.getLastChangeType() === 'insert-fragment';

    if (
      !isEqual(
        convertToRaw(editorState.getCurrentContent()),
        convertToRaw(this.state.editorState.getCurrentContent()),
      )
    ) {
      if (shouldFilterPaste) {
        let filteredState = editorState;
        filteredState = filterEditorState(
          {
            blocks: [],
            styles: [],
            entities: [
              {
                type: 'LINK',
                attributes: ['url'],
              },
            ],
            whitespacedCharacters: [],
          },
          filteredState,
        );
        editorState = filteredState;
      }
      this.props.onChangeBlock(this.props.block, {
github springload / draftail / lib / api / behavior.js View on Github external
editorState: EditorState,
  ) {
    const enabledEntityTypes = entityTypes.slice();
    const whitespacedCharacters = ["\t", "📷"];

    if (enableHorizontalRule) {
      enabledEntityTypes.push({
        type: ENTITY_TYPE.HORIZONTAL_RULE,
      });
    }

    if (!enableLineBreak) {
      whitespacedCharacters.push("\n");
    }

    return filterEditorState(
      {
        blocks: blockTypes.map((b) => b.type),
        styles: inlineStyles.map((s) => s.type),
        entities: enabledEntityTypes,
        maxNesting: maxListNesting,
        whitespacedCharacters,
      },
      editorState,
    );
  },
};

draftjs-filters

Filter Draft.js content to preserve only the formatting you allow

MIT
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis

Popular draftjs-filters functions