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
dab4e6fb
Commit
dab4e6fb
authored
Jul 04, 2025
by
Яков
Browse files
fix
parent
bbaa6d76
Changes
2
Show whitespace changes
Inline
Side-by-side
package.json
View file @
dab4e6fb
{
{
"name"
:
"react-ag-qeditor"
,
"name"
:
"react-ag-qeditor"
,
"version"
:
"1.0.9
8
"
,
"version"
:
"1.0.9
9
"
,
"description"
:
"WYSIWYG html editor"
,
"description"
:
"WYSIWYG html editor"
,
"author"
:
"atma"
,
"author"
:
"atma"
,
"license"
:
"
MIT
"
,
"license"
:
"
MIT
"
,
...
...
src/extensions/Image.jsx
View file @
dab4e6fb
...
@@ -105,10 +105,27 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select
...
@@ -105,10 +105,27 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select
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
)
{
console
.
warn
(
'
Image has invalid natural dimensions, retrying...
'
);
setTimeout
(
initImageSize
,
100
);
// Повторная попытка через 100 мс
return
;
}
// Рассчитываем начальные размеры с учетом максимальной ширины редактора
let
initialWidth
=
naturalWidth
;
let
initialHeight
=
naturalHeight
;
if
(
initialWidth
>
editorWidth
)
{
const
ratio
=
editorWidth
/
initialWidth
;
initialWidth
=
editorWidth
;
initialHeight
=
Math
.
round
(
initialHeight
*
ratio
);
}
safeUpdateAttributes
({
safeUpdateAttributes
({
width
:
natur
alWidth
,
width
:
initi
alWidth
,
height
:
natur
alHeight
,
height
:
initi
alHeight
,
'
data-node-id
'
:
node
.
attrs
[
'
data-node-id
'
]
||
Math
.
random
().
toString
(
36
).
substr
(
2
,
9
)
'
data-node-id
'
:
node
.
attrs
[
'
data-node-id
'
]
||
`img-
${
Date
.
now
()}
-
${
Math
.
random
().
toString
(
36
).
substr
(
2
,
9
)
}
`
});
});
isInitialized
.
current
=
true
;
isInitialized
.
current
=
true
;
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -116,14 +133,21 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select
...
@@ -116,14 +133,21 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select
}
}
};
};
const
handleLoad
=
()
=>
{
// Добавляем небольшую задержку для гарантированного получения размеров
setTimeout
(
initImageSize
,
50
);
};
if
(
imgRef
.
current
.
complete
)
{
if
(
imgRef
.
current
.
complete
)
{
initImageSize
();
handleLoad
();
}
else
{
}
else
{
imgRef
.
current
.
onload
=
initImageSize
;
imgRef
.
current
.
addEventListener
(
'
load
'
,
handleLoad
)
;
}
}
return
()
=>
{
return
()
=>
{
if
(
imgRef
.
current
)
imgRef
.
current
.
onload
=
null
;
if
(
imgRef
.
current
)
{
imgRef
.
current
.
removeEventListener
(
'
load
'
,
handleLoad
);
}
};
};
},
[
node
.
attrs
.
width
,
node
.
attrs
.
height
,
node
.
attrs
[
'
data-node-id
'
]]);
},
[
node
.
attrs
.
width
,
node
.
attrs
.
height
,
node
.
attrs
[
'
data-node-id
'
]]);
...
...
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