Commit b22d9645 by Яков

fix

parent dab4e6fb
{ {
"name": "react-ag-qeditor", "name": "react-ag-qeditor",
"version": "1.0.99", "version": "1.0.100",
"description": "WYSIWYG html editor", "description": "WYSIWYG html editor",
"author": "atma", "author": "atma",
"license": "MIT", "license": "MIT",
......
...@@ -101,18 +101,27 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select ...@@ -101,18 +101,27 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select
const initImageSize = () => { const initImageSize = () => {
try { try {
// Если размеры уже заданы в атрибутах - используем их
if (node.attrs.width && node.attrs.height) {
safeUpdateAttributes({
width: node.attrs.width,
height: node.attrs.height,
'data-node-id': node.attrs['data-node-id'] || `img-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
});
isInitialized.current = true;
return;
}
const { width: editorWidth } = getEditorDimensions(); const { width: editorWidth } = getEditorDimensions();
const naturalWidth = imgRef.current.naturalWidth; const naturalWidth = imgRef.current.naturalWidth;
const naturalHeight = imgRef.current.naturalHeight; const naturalHeight = imgRef.current.naturalHeight;
// Проверяем, что изображение загружено и имеет корректные размеры
if (naturalWidth <= 0 || naturalHeight <= 0) { if (naturalWidth <= 0 || naturalHeight <= 0) {
console.warn('Image has invalid natural dimensions, retrying...'); console.warn('Image has invalid natural dimensions, retrying...');
setTimeout(initImageSize, 100); // Повторная попытка через 100 мс setTimeout(initImageSize, 100);
return; return;
} }
// Рассчитываем начальные размеры с учетом максимальной ширины редактора
let initialWidth = naturalWidth; let initialWidth = naturalWidth;
let initialHeight = naturalHeight; let initialHeight = naturalHeight;
...@@ -134,7 +143,6 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select ...@@ -134,7 +143,6 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select
}; };
const handleLoad = () => { const handleLoad = () => {
// Добавляем небольшую задержку для гарантированного получения размеров
setTimeout(initImageSize, 50); setTimeout(initImageSize, 50);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment