From 411845d480135611b784616af031cac09277af94 Mon Sep 17 00:00:00 2001 From: swve Date: Mon, 28 Apr 2025 21:25:55 +0200 Subject: [PATCH] feat: add alignment options to ImageBlock component for improved layout control --- .../Editor/Extensions/Image/ImageBlock.ts | 3 + .../Extensions/Image/ImageBlockComponent.tsx | 78 +++++++++++++++---- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/apps/web/components/Objects/Editor/Extensions/Image/ImageBlock.ts b/apps/web/components/Objects/Editor/Extensions/Image/ImageBlock.ts index caff7013..abc7dc15 100644 --- a/apps/web/components/Objects/Editor/Extensions/Image/ImageBlock.ts +++ b/apps/web/components/Objects/Editor/Extensions/Image/ImageBlock.ts @@ -17,6 +17,9 @@ export default Node.create({ size: { width: 300, }, + alignment: { + default: 'center', + }, } }, diff --git a/apps/web/components/Objects/Editor/Extensions/Image/ImageBlockComponent.tsx b/apps/web/components/Objects/Editor/Extensions/Image/ImageBlockComponent.tsx index fb985d78..5227b95c 100644 --- a/apps/web/components/Objects/Editor/Extensions/Image/ImageBlockComponent.tsx +++ b/apps/web/components/Objects/Editor/Extensions/Image/ImageBlockComponent.tsx @@ -1,7 +1,7 @@ import { NodeViewWrapper } from '@tiptap/react' import React, { useEffect } from 'react' import { Resizable } from 're-resizable' -import { AlertTriangle, Image, Download } from 'lucide-react' +import { AlertTriangle, Image, Download, AlignLeft, AlignCenter, AlignRight } from 'lucide-react' import { uploadNewImageFile } from '../../../../../services/blocks/Image/images' import { getActivityBlockMediaDirectory } from '@services/media/media' import { useOrg } from '@components/Contexts/OrgContext' @@ -29,10 +29,12 @@ function ImageBlockComponent(props: any) { const [imageSize, setImageSize] = React.useState({ width: props.node.attrs.size ? props.node.attrs.size.width : 300, }) + const [alignment, setAlignment] = React.useState(props.node.attrs.alignment || 'center') const fileId = blockObject ? `${blockObject.content.file_id}.${blockObject.content.file_format}` : null + const handleImageChange = (event: React.ChangeEvent) => { setImage(event.target.files[0]) } @@ -49,6 +51,7 @@ function ImageBlockComponent(props: any) { props.updateAttributes({ blockObject: object, size: imageSize, + alignment: alignment, }) } @@ -75,8 +78,26 @@ function ImageBlockComponent(props: any) { document.body.removeChild(link); }; + const handleAlignmentChange = (newAlignment: string) => { + setAlignment(newAlignment); + props.updateAttributes({ + alignment: newAlignment, + }); + }; + useEffect(() => {}, [course, org]) + const getAlignmentClass = () => { + switch (alignment) { + case 'left': + return 'justify-start'; + case 'right': + return 'justify-end'; + default: + return 'justify-center'; + } + }; + return ( @@ -85,7 +106,7 @@ function ImageBlockComponent(props: any) { {blockObject && isEditable && ( -
+
- +
+ +
+ + + +
+
)} {blockObject && !isEditable && ( -
+