Commit 83e51387 by Яков

fix

parent 6911e026
{ {
"name": "react-ag-qeditor", "name": "react-ag-qeditor",
"version": "1.0.90", "version": "1.0.91",
"description": "WYSIWYG html editor", "description": "WYSIWYG html editor",
"author": "atma", "author": "atma",
"license": "MIT", "license": "MIT",
......
...@@ -357,28 +357,48 @@ const ResizableImageExtension = TipTapImage.extend({ ...@@ -357,28 +357,48 @@ const ResizableImageExtension = TipTapImage.extend({
}, },
renderHTML({ HTMLAttributes }) { renderHTML({ HTMLAttributes }) {
const align = HTMLAttributes.align || 'left'; // Получаем align из атрибутов, учитывая data-align как fallback
const isWrap = ['wrap-left', 'wrap-right'].includes(align); const align = HTMLAttributes.align ||
const floatDirection = isWrap ? align.split('-')[1] : ['left', 'right'].includes(align) ? align : 'none'; HTMLAttributes['data-align'] ||
'left';
// Определяем, нужно ли применять float
const floatValue = align.startsWith('wrap-') ? align.split('-')[1] :
['left', 'right'].includes(align) ? align :
'none';
// Определяем margin в зависимости от выравнивания
let marginValue;
switch(align) {
case 'left':
case 'wrap-left':
marginValue = '0 1rem 1rem 0';
break;
case 'right':
case 'wrap-right':
marginValue = '0 0 1rem 1rem';
break;
case 'center':
marginValue = '0.5rem auto';
break;
default:
marginValue = '0';
}
return ['span', { return ['span', {
'data-type': 'resizable-image', 'data-type': 'resizable-image',
'data-image-wrapper': true, 'data-image-wrapper': true,
'data-align': align, // Сохраняем значение align в data-атрибуте
style: ` style: `
display: ${align === 'center' ? 'block' : 'inline-block'}; display: ${align === 'center' ? 'block' : 'inline-block'};
float: ${floatDirection}; float: ${floatValue};
margin: ${align === 'left' ? '0 1rem 1rem 0' : margin: ${marginValue};
align === 'right' ? '0 0 1rem 1rem' : shape-outside: ${align.startsWith('wrap-') ? 'margin-box' : 'none'};
align === 'wrap-left' ? '0 1rem 1rem 0' :
align === 'wrap-right' ? '0 0 1rem 1rem' :
align === 'center' ? '0.5rem auto' : '0'};
shape-outside: ${isWrap ? 'margin-box' : 'none'};
vertical-align: top; vertical-align: top;
position: relative; position: relative;
z-index: 1; z-index: 1;
${align === 'center' ? 'width: 100%; text-align: center;' : ''} ${align === 'center' ? 'width: 100%; text-align: center;' : ''}
`, `
'data-align': align
}, ['img', { }, ['img', {
...HTMLAttributes, ...HTMLAttributes,
style: ` style: `
...@@ -387,7 +407,9 @@ const ResizableImageExtension = TipTapImage.extend({ ...@@ -387,7 +407,9 @@ const ResizableImageExtension = TipTapImage.extend({
margin: ${align === 'center' ? '0 auto' : '0'}; margin: ${align === 'center' ? '0 auto' : '0'};
max-width: 100%; max-width: 100%;
height: auto; height: auto;
` `,
// Убедимся, что align также передаётся в img
'data-align': align
}]]; }]];
}, },
......
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