Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Make the caption plugins independent of the ImageNode/ImagePlugin #3172

Open
GermanJablo opened this issue Oct 13, 2022 · 0 comments
Labels
enhancement Improvement over existing feature images

Comments

@GermanJablo
Copy link
Contributor

In order for the image component to be modularizable, it would be nice if the plugins used by the caption editor could be sent as children of the ImagePlugin or as a property.
In this way, people could customize the behavior of captions without having to modify their internal structure.

I'm thinking something like:

<ImagesPlugin
captionPlugins={
<>
  <AutoFocusPlugin />
  <MentionsPlugin />
  <LinkPlugin />
  <EmojisPlugin />
  <HashtagPlugin />
  <KeywordsPlugin />
{
  isCollabActive ? (
    <CollaborationPlugin
      id={caption.getKey()}
      providerFactory={createWebsocketProvider}
      shouldBootstrap={true}
    />
  ) : (
    <HistoryPlugin externalHistoryState={historyState} />
  );
}
<RichTextPlugin
  contentEditable={<ContentEditable className="ImageNode__contentEditable" />}
  placeholder={
    <Placeholder className="ImageNode__placeholder">
      Enter a caption...
    </Placeholder>
  }
/>;
{
  showNestedEditorTreeView === true ? <TreeViewPlugin /> : null;
}
</>;
}

/>

Note that the new table plugin uses a similar strategy for the cell plugins.
LexicalComposer, LexicalNestedComposer, and TableContext use very similar logic. Considering that similar logic could now be useful for images and that this pattern can plausibly be repeated in almost any nested editor, I think it would be nice to find a way to make all these contexts more reusable.

For my part, I was trying for a while to adapt the TableContext, but some doubts arose.
For example, I don't understand why <TableContext> is created in App.tsx when it is just initialized in <TablePlugin> and I think it is not used by any other plugin. I think it could be simplified to something like
<TablePlugin cellPlugins={...}/>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement over existing feature images
Projects
None yet
Development

No branches or pull requests

2 participants