Skip to content

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

editor: store image size on first load

Abdullah Attab1f79e338fb5
diff --git a/packages/editor/src/extensions/image/component.tsx b/packages/editor/src/extensions/image/component.tsx
index e60d44e32..a31f1e769 100644
--- a/packages/editor/src/extensions/image/component.tsx
+++ b/packages/editor/src/extensions/image/component.tsx
@@ -44,7 +44,7 @@ export function ImageComponent(
) {
const { editor, node, selected } = props;
const isMobile = useIsMobile();
- const { src, alt, title, width, height, align } = node.attrs;
+ const { src, alt, title, width, height, align, hash } = node.attrs;
const float = isMobile ? false : node.attrs.float;
const imageRef = useRef<HTMLImageElement>(null);
@@ -64,7 +64,6 @@ export function ImageComponent(
downloadOptions
);
setSource(url);
- console.log(url, size, blob, type);
editor.current?.commands.updateImage(
{ src },
{ src: await toDataURL(blob), size, type }
@@ -103,7 +102,8 @@ export function ImageComponent(
{!source || error ? (
<Flex
sx={{
- width,
+ width: width || "100%",
+ height: height || "100%",
maxWidth: "100%",
minWidth: 135,
bg: "bgSecondary",
@@ -125,7 +125,7 @@ export function ImageComponent(
? Icons.imageDownload
: Icons.image
}
- size={72}
+ size={width ? width * 0.2 : 72}
color="gray"
/>
@@ -228,6 +228,15 @@ export function ImageComponent(
: "2px solid transparent",
borderRadius: "default"
}}
+ onLoad={(e) => {
+ const { clientWidth, clientHeight } = e.currentTarget;
+ if (!width && !height) {
+ editor.current?.commands.updateImage(
+ { src },
+ { width: clientWidth, height: clientHeight }
+ );
+ }
+ }}
{...props}
/>
</Resizer>
diff --git a/packages/editor/src/extensions/image/image.ts b/packages/editor/src/extensions/image/image.ts
index 22701be68..a023f6954 100644
--- a/packages/editor/src/extensions/image/image.ts
+++ b/packages/editor/src/extensions/image/image.ts
@@ -59,7 +59,7 @@ declare module "@tiptap/core" {
insertImage: (options: ImageAttributes) => ReturnType;
updateImage: (
query: { src?: string; hash?: string },
- options: ImageAttributes & { preventUpdate?: boolean }
+ options: Partial<ImageAttributes> & { preventUpdate?: boolean }
) => ReturnType;
setImageAlignment: (options: ImageAlignmentOptions) => ReturnType;
setImageSize: (options: ImageSizeOptions) => ReturnType;