Commit 7c036f68 by Яков

fix

parent e6cde1d6
{
"name": "react-ag-qeditor",
"version": "1.0.88",
"version": "1.0.89",
"description": "WYSIWYG html editor",
"author": "atma",
"license": "MIT",
......
......@@ -20,32 +20,78 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos }) => {
aspectRatio: 1
});
// Добавляем прозрачный нулевой пробел после изображения
// Добавляем прозрачный нулевой пробел после изображения (исправленная версия)
useEffect(() => {
if (!editor || !getPos) return;
if (!editor?.isEditable || typeof getPos !== 'function') return;
const insertZeroWidthSpace = () => {
try {
const pos = getPos();
if (typeof pos !== 'number' || pos < 0) return;
const pos = getPos() + 1;
const doc = editor.state.doc;
const insertPos = pos + 1; // Позиция после изображения
// Проверяем, что позиция существует в документе
if (insertPos >= doc.content.size) return;
if (doc.nodeSize > pos && doc.nodeAt(pos)?.textContent !== '\u200B') {
editor.commands.insertContentAt(pos, {
// Проверяем, не добавлен ли уже нулевой пробел
const nextNode = doc.nodeAt(insertPos);
if (nextNode?.textContent === '\u200B') return;
// Вставляем пробел с небольшой задержкой для стабильности
setTimeout(() => {
if (editor.isDestroyed) return;
editor.commands.insertContentAt(insertPos, {
type: 'text',
text: '\u200B' // Невидимый нулевой пробел
text: '\u200B'
});
}, 50);
} catch (error) {
console.warn('Error inserting zero-width space:', error);
}
};
const timer = setTimeout(insertZeroWidthSpace, 100);
return () => clearTimeout(timer);
}, [editor, getPos]);
// Инициализация размеров
// Инициализация размеров (исправленная версия)
useEffect(() => {
if (imgRef.current && !isInitialized.current) {
if (!imgRef.current || isInitialized.current) return;
const initImageSize = () => {
try {
const width = node.attrs.width || imgRef.current.naturalWidth;
const height = node.attrs.height || imgRef.current.naturalHeight;
// Проверяем валидность размеров перед обновлением
if (width > 0 && height > 0) {
updateAttributes({
width: Math.round(width),
height: Math.round(height)
});
isInitialized.current = true;
}
} catch (error) {
console.warn('Error initializing image size:', error);
}
};
// Если изображение уже загружено
if (imgRef.current.complete) {
initImageSize();
} else {
// Если еще загружается - ждем события onLoad
imgRef.current.onload = initImageSize;
}
return () => {
// Очищаем обработчик при размонтировании
if (imgRef.current) {
imgRef.current.onload = null;
}
};
}, [node.attrs.width, node.attrs.height, updateAttributes]);
const handleResizeStart = (direction) => (e) => {
......
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