Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
lib
react-ag-qeditor
Commits
7c036f68
Commit
7c036f68
authored
Jun 30, 2025
by
Яков
Browse files
fix
parent
e6cde1d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
package.json
View file @
7c036f68
{
{
"name"
:
"react-ag-qeditor"
,
"name"
:
"react-ag-qeditor"
,
"version"
:
"1.0.8
8
"
,
"version"
:
"1.0.8
9
"
,
"description"
:
"WYSIWYG html editor"
,
"description"
:
"WYSIWYG html editor"
,
"author"
:
"atma"
,
"author"
:
"atma"
,
"license"
:
"
MIT
"
,
"license"
:
"
MIT
"
,
...
...
src/extensions/Image.jsx
View file @
7c036f68
...
@@ -20,32 +20,78 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos }) => {
...
@@ -20,32 +20,78 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos }) => {
aspectRatio
:
1
aspectRatio
:
1
});
});
// Добавляем прозрачный нулевой пробел после изображения
// Добавляем прозрачный нулевой пробел после изображения
(исправленная версия)
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
!
editor
||
!
getPos
)
return
;
if
(
!
editor
?.
isEditable
||
typeof
getPos
!==
'
function
'
)
return
;
const
pos
=
getPos
()
+
1
;
const
insertZeroWidthSpace
=
()
=>
{
const
doc
=
editor
.
state
.
doc
;
try
{
const
pos
=
getPos
();
if
(
typeof
pos
!==
'
number
'
||
pos
<
0
)
return
;
if
(
doc
.
nodeSize
>
pos
&&
doc
.
nodeAt
(
pos
)?.
textContent
!==
'
\
u200B
'
)
{
const
doc
=
editor
.
state
.
doc
;
editor
.
commands
.
insertContentAt
(
pos
,
{
const
insertPos
=
pos
+
1
;
// Позиция после изображения
type
:
'
text
'
,
text
:
'
\
u200B
'
// Невидимый нулевой пробел
// Проверяем, что позиция существует в документе
});
if
(
insertPos
>=
doc
.
content
.
size
)
return
;
}
// Проверяем, не добавлен ли уже нулевой пробел
const
nextNode
=
doc
.
nodeAt
(
insertPos
);
if
(
nextNode
?.
textContent
===
'
\
u200B
'
)
return
;
// Вставляем пробел с небольшой задержкой для стабильности
setTimeout
(()
=>
{
if
(
editor
.
isDestroyed
)
return
;
editor
.
commands
.
insertContentAt
(
insertPos
,
{
type
:
'
text
'
,
text
:
'
\
u200B
'
});
},
50
);
}
catch
(
error
)
{
console
.
warn
(
'
Error inserting zero-width space:
'
,
error
);
}
};
const
timer
=
setTimeout
(
insertZeroWidthSpace
,
100
);
return
()
=>
clearTimeout
(
timer
);
},
[
editor
,
getPos
]);
},
[
editor
,
getPos
]);
// Инициализация размеров
// Инициализация размеров
(исправленная версия)
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
imgRef
.
current
&&
!
isInitialized
.
current
)
{
if
(
!
imgRef
.
current
||
isInitialized
.
current
)
return
;
const
width
=
node
.
attrs
.
width
||
imgRef
.
current
.
naturalWidth
;
const
height
=
node
.
attrs
.
height
||
imgRef
.
current
.
naturalHeight
;
const
initImageSize
=
()
=>
{
updateAttributes
({
try
{
width
:
Math
.
round
(
width
),
const
width
=
node
.
attrs
.
width
||
imgRef
.
current
.
naturalWidth
;
height
:
Math
.
round
(
height
)
const
height
=
node
.
attrs
.
height
||
imgRef
.
current
.
naturalHeight
;
});
isInitialized
.
current
=
true
;
// Проверяем валидность размеров перед обновлением
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
]);
},
[
node
.
attrs
.
width
,
node
.
attrs
.
height
,
updateAttributes
]);
const
handleResizeStart
=
(
direction
)
=>
(
e
)
=>
{
const
handleResizeStart
=
(
direction
)
=>
(
e
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment