-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add more built-in features for "Insert image" menu button, for @tiptap/extension-image #136
Comments
👋🏻 Do you have a simple example of triggering a file upload when clicking the Insert image menu button? |
Hi @devth, I don't have one off hand, though I plan to add one soon. I think an approach like this https://medium.com/web-dev-survey-from-kyoto/how-to-customize-the-file-upload-button-in-react-b3866a5973d8 (https://codesandbox.io/embed/how-to-customize-file-upload-buttons-in-react-wthkrz?codemirror=1) is similar to what I had in mind, except swapping the |
@sjdemartini awesome, thanks so much! I’ll play around and see what I can come up with. |
@devth I've released a new version 1.8.0 which includes a new component I've also updated the demo to show how to use drag-and-drop and pasting of image files (notes on this are in the README here). Hope that's useful! |
@sjdemartini this looks awesome! thanks. |
@rextambua This comment doesn't seem to be related to the original issue here—please create new issues rather than changing the topic if you have a problem. In this case though, it appears your issue is that you haven't installed and added the necessary extensions (notably |
sorry and thanks, i will read this material and if need arises i will create a new issue |
Since it's common to get questions/"issues" pertaining to this and is important to help diagnose as well. e.g. #187, #174, #136 (comment)
Since it's common to get questions/"issues" pertaining to this and is important to help diagnose as well. e.g. #187, #174, #136 (comment)
Hey @sjdemartini, quick question on this - when I use <div class="react-renderer node-image ProseMirror-selectednode" contenteditable="false" draggable="true">
<div data-node-view-wrapper="" style="white-space: normal; text-align: right; width: 100%;">
<div class="css-1fk4pfw-ResizableImageComponent-imageContainer">
<img src="https://firebasestorage.googleapis.com/v0/b/converge-mt.appspot.com/o/images%2Fuploads%2Facme%2Feditor%2FlxsKFckgYGPnfZImBWmJKQSp3cR2%2F1712845173502.IMG_5320.jpeg?alt=media&token=c174d23e-05ab-4b38-aa29-562f3e180e7f" height="auto" width="138" class="ProseMirror-selectednode css-1cxz5lg-ResizableImageComponent-image-ResizableImageComponent-imageSelected" data-drag-handle="true" style="aspect-ratio: 1 / 1;" />
<div class="css-e5u3zl-ResizableImageResizer-root-ResizableImageComponent-resizer"></div>
</div>
</div>
</div> But when I call <img height="auto" src="https://firebasestorage.googleapis.com/v0/b/converge-mt.appspot.com/o/images%2Fuploads%2Facme%2Feditor%2FlxsKFckgYGPnfZImBWmJKQSp3cR2%2F1712845173502.IMG_5320.jpeg?alt=media&token=c174d23e-05ab-4b38-aa29-562f3e180e7f" width="138" style="text-align: right; aspect-ratio: 1 / 1;" /> lacking the wrapper, which causes alignment to not work. I compared this to the official demo and that does not happen - the resulting HTML still contains a wrapper like: <div class="react-renderer node-image" contenteditable="false" draggable="true">
<div data-node-view-wrapper="" style="white-space: normal; text-align: right; width: 100%;">
<div class="css-1fk4pfw-ResizableImageComponent-imageContainer">
<img src="blob:https://3zl2l6-5173.csb.app/58bd9814-3f86-439d-bcfe-f215abd3fe60" height="auto" width="394" alt="snoop Samurai.jpeg" class="css-12r3bmv-ResizableImageComponent-image" data-drag-handle="true" style="aspect-ratio: 1 / 1;" />
</div>
</div>
</div> I am configuring Edit: I just noticed it uses |
@devth I'm not sure where you are referring to in saying that the CodeSandbox demo has In general, you should use Tiptap to render and display Tiptap content, like with |
One thing I'm trying to figure out is how I can replace anchor tags coming from tiptap const parseHtmlWithNextLink = (html: string) => {
return htmlParse(html, {
replace: (domNode) => {
if (domNode instanceof Element && domNode.attribs) {
if (domNode.name === "a") {
const props = attributesToProps(domNode.attribs);
return (
<Link legacyBehavior href={domNode.attribs.href} {...props}>
<a {...props}>{domToReact(domNode.children as DOMNode[])}</a>
</Link>
);
}
}
},
});
}; 🤔 |
An alternate solution I tried is to keep using const parseHtmlWithNextLink = (html: string) => {
return htmlParse(html, {
replace: (domNode) => {
if (domNode instanceof Element && domNode.attribs) {
// surround images with a div that respects alignment
const props = attributesToProps(domNode.attribs);
if (domNode.name === "img") {
const style = props.style;
const divStyle = {
width: "100%",
textAlign: style?.textAlign as CSSProperties["textAlign"],
};
return (
<div style={divStyle}>
<img
alt={props.alt as string}
{...attributesToProps(domNode.attribs)}
/>
</div>
);
}
// turn anchor tags into Next.js Link elements for client-side routing
if (domNode.name === "a") {
return (
<Link legacyBehavior href={domNode.attribs.href} {...props}>
<a {...props}>{domToReact(domNode.children as DOMNode[])}</a>
</Link>
);
}
}
},
});
}; Not sure this is a good idea, but it "works". |
Great work firstly . Thanks. |
Oops Ive now included a MUI diag box for insert Images. However upon inserting a Transparent PNG the background showa white. Any think I may be missing ? |
@sjdemartini would be great if you could help let me know if there is something missing WRT adding transparent images |
@pymenow There is not a specific built-in way to add an image from a URL in mui-tiptap, but you can do it yourself with your own mui-tiptap MenuButton, MUI Dialog, etc. as you seem to be suggesting. In terms of transparent images, mui-tiptap currently has behavior similar to Chrome, which is to add a light grey background to all (transparent) images, as this tends to be useful since most images are created on a light background and will help make them readable even in dark mode. (Though of course some images, likely a minority of them, will have the opposite problem.) See the notes here for more of the behavior details and rationale Lines 489 to 516 in 9e4bbb5
You can override the styles by targeting |
Right now, there's a general-purpose "insert image" button via
MenuButtonAddImage
. You provide your ownonClick
(where you could use your own interface to type in a URL, or you could trigger a file upload), like in the simple example in the internal demo.As originally mentioned/requested in #52, we might also want to add support for more functionality/UI built into mui-tiptap, with:
MenuButtonImageUpload
andinsertImages
util for handling/inserting user-uploaded images #147, available as of mui-tiptap v1.8.0)See example screenshots here #52 (comment)
The text was updated successfully, but these errors were encountered: