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

Restricted the ability for user to resize images with respect to EditorContent width #914

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ export default Node.create({
name: "image",

addOptions() {
return {
HTMLAttributes: {},
openImageInNewTab: true,
};
return { HTMLAttributes: {}, openImageInNewTab: true };
},

group: "block",
Expand Down Expand Up @@ -82,11 +79,7 @@ export default Node.create({
},

parseHTML() {
return [
{
tag: "figure",
},
];
return [{ tag: "figure" }];
},

renderHTML({ node, HTMLAttributes }) {
Expand Down
11 changes: 11 additions & 0 deletions src/components/Editor/CustomExtensions/Image/ImageComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ const ImageComponent = ({
? figureRef.current.querySelector("figcaption>div")?.textContent
: alt;

const editorElement = figureRef.current?.closest(".neeto-editor");
const maxImageWidth = editorElement?.offsetWidth - 50;

const handleResizeStop = (_event, _direction, ref) => {
height = ref.offsetHeight;
width = ref.offsetWidth;

if (width > maxImageWidth) {
width = maxImageWidth;
const aspectRatio = ref.offsetHeight / ref.offsetWidth;
height = width * aspectRatio;
}
setCaptionWidth(width);
view.dispatch(
view.state.tr.setNodeMarkup(
getPos(),
Expand All @@ -57,6 +67,7 @@ const ImageComponent = ({
<Resizable
lockAspectRatio
className="neeto-editor__image"
minWidth="100px"
size={{ height, width }}
onResizeStop={handleResizeStop}
onResize={(_event, _direction, ref) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,9 @@ const useCustomExtensions = ({
if (!isEmpty(mentions)) {
const items = createMentionSuggestions(mentions);

customExtensions.push(
Mention.configure({
suggestion: {
items,
},
})
);
customExtensions.push(Mention.configure({ suggestion: { items } }));

customExtensions.push(
SpecialMentions.configure({
suggestion: {
items,
},
})
);
customExtensions.push(SpecialMentions.configure({ suggestion: { items } }));
}

if (!isEmpty(variables)) {
Expand Down
Loading