fix: convert image size to string (#5717)

This commit is contained in:
Aaryan Khandelwal 2024-09-27 20:39:50 +05:30 committed by GitHub
parent ec08fb078d
commit 04686d1721
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 4 deletions

View file

@ -11,7 +11,10 @@ export const CustomImageBlock: React.FC<CustomImageNodeViewProps> = (props) => {
const { node, updateAttributes, selected, getPos, editor } = props; const { node, updateAttributes, selected, getPos, editor } = props;
const { src, width, height } = node.attrs; const { src, width, height } = node.attrs;
const [size, setSize] = useState({ width: width || "35%", height: height || "auto" }); const [size, setSize] = useState({
width: width?.toString() || "35%",
height: height?.toString() || "auto",
});
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [initialResizeComplete, setInitialResizeComplete] = useState(false); const [initialResizeComplete, setInitialResizeComplete] = useState(false);
const isShimmerVisible = isLoading || !initialResizeComplete; const isShimmerVisible = isLoading || !initialResizeComplete;
@ -56,7 +59,10 @@ export const CustomImageBlock: React.FC<CustomImageNodeViewProps> = (props) => {
}, [width, height, updateAttributes]); }, [width, height, updateAttributes]);
useLayoutEffect(() => { useLayoutEffect(() => {
setSize({ width, height }); setSize({
width: width?.toString(),
height: height?.toString(),
});
}, [width, height]); }, [width, height]);
const handleResizeStart = useCallback( const handleResizeStart = useCallback(

View file

@ -15,8 +15,8 @@ export type CustomImageNodeViewProps = {
node: ProsemirrorNode & { node: ProsemirrorNode & {
attrs: { attrs: {
src: string; src: string;
width: string; width: number | string;
height: string; height: number | string;
}; };
}; };
updateAttributes: (attrs: Record<string, any>) => void; updateAttributes: (attrs: Record<string, any>) => void;