Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
);
}
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, {
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,
);
},
};