Skip to content

Commit 03177d2

Browse files
fix: Errors when hovering image block while editor is uneditable (#533)
* Fixed errors when hovering image block while editor is uneditable * Small fix
1 parent 6bb6271 commit 03177d2

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

packages/core/src/blocks/ImageBlockContent/ImageBlockContent.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ export const renderImage = (
148148
// offset from when the resize began, and which resize handle is being used.
149149
const windowMouseMoveHandler = (event: MouseEvent) => {
150150
if (!resizeParams) {
151+
if (
152+
!editor.isEditable &&
153+
imageWrapper.contains(leftResizeHandle) &&
154+
imageWrapper.contains(rightResizeHandle)
155+
) {
156+
imageWrapper.removeChild(leftResizeHandle);
157+
imageWrapper.removeChild(rightResizeHandle);
158+
}
159+
151160
return;
152161
}
153162

@@ -192,20 +201,22 @@ export const renderImage = (
192201
// Stops mouse movements from resizing the image and updates the block's
193202
// `width` prop to the new value.
194203
const windowMouseUpHandler = (event: MouseEvent) => {
195-
if (!resizeParams) {
196-
return;
197-
}
198-
199204
// Hides the drag handles if the cursor is no longer over the image.
200205
if (
201-
(!event.target || !imageWrapper.contains(event.target as Node)) &&
206+
(!event.target ||
207+
!imageWrapper.contains(event.target as Node) ||
208+
!editor.isEditable) &&
202209
imageWrapper.contains(leftResizeHandle) &&
203210
imageWrapper.contains(rightResizeHandle)
204211
) {
205212
imageWrapper.removeChild(leftResizeHandle);
206213
imageWrapper.removeChild(rightResizeHandle);
207214
}
208215

216+
if (!resizeParams) {
217+
return;
218+
}
219+
209220
resizeParams = undefined;
210221

211222
editor.updateBlock(block, {
@@ -235,9 +246,6 @@ export const renderImage = (
235246
if (editor.isEditable) {
236247
imageWrapper.appendChild(leftResizeHandle);
237248
imageWrapper.appendChild(rightResizeHandle);
238-
} else {
239-
imageWrapper.removeChild(leftResizeHandle);
240-
imageWrapper.removeChild(rightResizeHandle);
241249
}
242250
};
243251
// Hides the resize handles when the cursor leaves the image, unless the
@@ -254,8 +262,14 @@ export const renderImage = (
254262
return;
255263
}
256264

257-
imageWrapper.removeChild(leftResizeHandle);
258-
imageWrapper.removeChild(rightResizeHandle);
265+
if (
266+
editor.isEditable &&
267+
imageWrapper.contains(leftResizeHandle) &&
268+
imageWrapper.contains(rightResizeHandle)
269+
) {
270+
imageWrapper.removeChild(leftResizeHandle);
271+
imageWrapper.removeChild(rightResizeHandle);
272+
}
259273
};
260274

261275
// Sets the resize params, allowing the user to begin resizing the image by

0 commit comments

Comments
 (0)