From 552d21046e3f8549200f59da9cad5f1019f0c4c9 Mon Sep 17 00:00:00 2001 From: swve Date: Wed, 26 Feb 2025 10:20:41 +0100 Subject: [PATCH] feat: Improve ImageBlockComponent with responsive resizing and layout --- .../Extensions/Image/ImageBlockComponent.tsx | 103 +++++++++++------- 1 file changed, 64 insertions(+), 39 deletions(-) diff --git a/apps/web/components/Objects/Editor/Extensions/Image/ImageBlockComponent.tsx b/apps/web/components/Objects/Editor/Extensions/Image/ImageBlockComponent.tsx index 786a7384..50219349 100644 --- a/apps/web/components/Objects/Editor/Extensions/Image/ImageBlockComponent.tsx +++ b/apps/web/components/Objects/Editor/Extensions/Image/ImageBlockComponent.tsx @@ -18,7 +18,7 @@ function ImageBlockComponent(props: any) { const course = useCourse() as any const editorState = useEditorProvider() as any const session = useLHSession() as any - const access_token = session?.data?.tokens?.access_token; + const access_token = session?.data?.tokens?.access_token; const isEditable = editorState.isEditable const [image, setImage] = React.useState(null) @@ -29,6 +29,7 @@ function ImageBlockComponent(props: any) { const [imageSize, setImageSize] = React.useState({ width: props.node.attrs.size ? props.node.attrs.size.width : 300, }) + const fileId = blockObject ? `${blockObject.content.file_id}.${blockObject.content.file_format}` : null @@ -54,48 +55,70 @@ function ImageBlockComponent(props: any) { useEffect(() => {}, [course, org]) return ( - + - {blockObject && ( - { - props.updateAttributes({ - size: { - width: imageSize.width + d.width, + {blockObject && isEditable && ( +
+ + }} + style={{ + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + height: '100%', + maxWidth: '100%', + }} + maxWidth="100%" + minWidth={200} + enable={{ right: true }} + onResizeStop={(e, direction, ref, d) => { + const newWidth = Math.min(imageSize.width + d.width, ref.parentElement?.clientWidth || 1000); + props.updateAttributes({ + size: { + width: newWidth, + }, + }) + setImageSize({ + width: newWidth, + }) + }} + > + + +
+ )} + + {blockObject && !isEditable && ( +
- +
)} + {isLoading && (