jpuri / react-draft-wysiwyg

A Wysiwyg editor build on top of ReactJS and DraftJS. https://jpuri.github.io/react-draft-wysiwyg
MIT License
6.38k stars 1.15k forks source link

customBlockRenderFunc how to getEditorState currentContent #1375

Open sydneywu opened 1 year ago

sydneywu commented 1 year ago

In the getBlockRendererFunc, the image is able to access currentContent. Code below. But this is not available to customBlockRenderer.

const getBlockRenderFunc = (config, customBlockRenderer) => (block) => {
  if (typeof customBlockRenderer === 'function') {
    const renderedComponent = customBlockRenderer(block, config, config.getEditorState);
    if (renderedComponent) return renderedComponent;
  }
  if (block.getType() === 'atomic') {
    const contentState = config.getEditorState().getCurrentContent();
    const entity = contentState.getEntity(block.getEntityAt(0));
    if (entity && entity.type === 'IMAGE') {
      return {
        component: getImageComponent(config),
        editable: false,
      };
    } else if (entity && entity.type === 'EMBEDDED_LINK') {
      return {
        component: Embedded,
        editable: false,
      };
    }
  }
  return undefined;
};

CustomBlockRenderer type defintion is as so:

customBlockRenderFunc?(block: ContentBlock): any;

Should it be updated to

customBlockRenderFunc?(block: ContentBlock, config: object, getEditorState: Function): any;