Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: fix image resizing

Abdullah Attaa3c24bc66685
diff --git a/packages/editor/src/components/resizer/index.tsx b/packages/editor/src/components/resizer/index.tsx
index 7f345f088..af7ad99f0 100644
--- a/packages/editor/src/components/resizer/index.tsx
+++ b/packages/editor/src/components/resizer/index.tsx
@@ -30,15 +30,25 @@ type ResizerProps = {
height?: number;
handleColor?: keyof SchemeColors;
onResize: (width: number, height: number) => void;
+ style?: React.CSSProperties;
};
export function Resizer(props: PropsWithChildren<ResizerProps>) {
- const { editor, selected, onResize, width, height, children, handleColor } =
- props;
+ const {
+ editor,
+ selected,
+ onResize,
+ width,
+ height,
+ children,
+ handleColor,
+ style
+ } = props;
if (!editor.isEditable) return <>{children}</>;
return (
<Resizable
+ style={style}
enable={{
bottom: false,
left: false,
diff --git a/packages/editor/src/extensions/image/component.tsx b/packages/editor/src/extensions/image/component.tsx
index ff149307a..edc394ba6 100644
--- a/packages/editor/src/extensions/image/component.tsx
+++ b/packages/editor/src/extensions/image/component.tsx
@@ -38,7 +38,7 @@ import {
} from "../../utils/downloader";
import { m, LazyMotion, domAnimation } from "framer-motion";
-export const AnimatedFlex = m(Flex);
+export const AnimatedImage = m(Image);
export function ImageComponent(
props: SelectionBasedReactNodeViewProps<
@@ -183,92 +183,89 @@ export function ImageComponent(
) : null}
</Flex>
) : (
- <AnimatedFlex
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- transition={{ duration: 0.5, ease: "easeIn" }}
- sx={{ mt: 1 }}
+ <Resizer
+ style={{ marginTop: 5 }}
+ editor={editor}
+ selected={selected}
+ width={width}
+ onResize={(width, height) => {
+ editor.commands.setImageSize({ width, height });
+ }}
>
- <Resizer
- editor={editor}
- selected={selected}
- width={width}
- onResize={(width, height) => {
- editor.commands.setImageSize({ width, height });
- }}
- >
- <DesktopOnly>
- {selected && (
- <Flex sx={{ position: "relative", justifyContent: "end" }}>
- <Flex
+ <DesktopOnly>
+ {selected && (
+ <Flex sx={{ position: "relative", justifyContent: "end" }}>
+ <Flex
+ sx={{
+ position: "absolute",
+ top: -40,
+ mb: 2,
+ alignItems: "end"
+ }}
+ >
+ <ToolbarGroup
+ editor={editor}
+ tools={[
+ hash ? "downloadAttachment" : "none",
+ "imageAlignLeft",
+ float ? "none" : "imageAlignCenter",
+ "imageAlignRight",
+ "imageProperties"
+ ]}
sx={{
- position: "absolute",
- top: -40,
- mb: 2,
- alignItems: "end"
+ boxShadow: "menu",
+ borderRadius: "default",
+ bg: "background"
}}
- >
- <ToolbarGroup
- editor={editor}
- tools={[
- hash ? "downloadAttachment" : "none",
- "imageAlignLeft",
- float ? "none" : "imageAlignCenter",
- "imageAlignRight",
- "imageProperties"
- ]}
- sx={{
- boxShadow: "menu",
- borderRadius: "default",
- bg: "background"
- }}
- />
- </Flex>
+ />
</Flex>
- )}
- </DesktopOnly>
- {selected && (
- <Icon
- className="drag-handle"
- data-drag-handle
- draggable
- path={Icons.dragHandle}
- color="black"
- sx={{
- cursor: "grab",
- position: "absolute",
- top: 1,
- left: 1,
- zIndex: 999
- }}
- />
+ </Flex>
)}
- <Image
- data-drag-image
- ref={imageRef}
- alt={alt}
- src={source}
- title={title}
+ </DesktopOnly>
+ {selected && (
+ <Icon
+ className="drag-handle"
+ data-drag-handle
+ draggable
+ path={Icons.dragHandle}
+ color="black"
sx={{
- width: editor.isEditable ? "100%" : width,
- height: editor.isEditable ? "100%" : height,
- border: selected
- ? "2px solid var(--primary)"
- : "2px solid transparent",
- borderRadius: "default"
- }}
- onLoad={(e) => {
- const { clientHeight, clientWidth } = e.currentTarget;
- if (!height && !width && !aspectRatio) {
- editor.current?.commands.updateImage(
- { src, hash },
- { aspectRatio: clientWidth / clientHeight }
- );
- }
+ cursor: "grab",
+ position: "absolute",
+ top: 1,
+ left: 1,
+ zIndex: 999
}}
/>
- </Resizer>
- </AnimatedFlex>
+ )}
+ <AnimatedImage
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1 }}
+ transition={{ duration: 0.5, ease: "easeIn" }}
+ data-drag-image
+ ref={imageRef}
+ alt={alt}
+ src={source}
+ title={title}
+ sx={{
+ width: editor.isEditable ? "100%" : width,
+ height: editor.isEditable ? "100%" : height,
+ border: selected
+ ? "2px solid var(--primary)"
+ : "2px solid transparent",
+ borderRadius: "default"
+ }}
+ onLoad={(e) => {
+ const { clientHeight, clientWidth } = e.currentTarget;
+ if (!height && !width && !aspectRatio) {
+ editor.current?.commands.updateImage(
+ { src, hash },
+ { aspectRatio: clientWidth / clientHeight }
+ );
+ }
+ }}
+ />
+ </Resizer>
)}
</LazyMotion>
</Box>