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
199d09d0
Commit
199d09d0
authored
Jul 14, 2025
by
Яков
Browse files
update
parent
3607e730
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/extensions/Image.jsx
View file @
199d09d0
...
...
@@ -2,7 +2,7 @@ import { NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react";
import
React
,
{
useEffect
,
useRef
,
useState
,
Fragment
}
from
"
react
"
;
import
TipTapImage
from
"
@tiptap/extension-image
"
;
import
{
Button
,
Modal
,
Input
}
from
'
antd
'
;
import
Icon
,
{
FontSizeOutlined
}
from
"
@ant-design/icons
"
;
import
{
FontSizeOutlined
}
from
"
@ant-design/icons
"
;
const
{
TextArea
}
=
Input
;
...
...
@@ -24,17 +24,26 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select
useEffect
(()
=>
{
if
(
!
editor
||
!
getPos
)
return
;
const
pos
=
getPos
()
+
1
;
let
pos
;
try
{
pos
=
getPos
();
if
(
typeof
pos
!==
'
number
'
)
return
;
}
catch
(
e
)
{
console
.
warn
(
'
getPos() failed:
'
,
e
);
return
;
}
const
doc
=
editor
.
state
.
doc
;
if
(
doc
.
nodeSize
>
pos
&&
doc
.
nodeAt
(
pos
)?.
textContent
!==
'
\
u200B
'
)
{
editor
.
commands
.
insertContentAt
(
pos
,
{
editor
.
commands
.
insertContentAt
(
pos
+
1
,
{
type
:
'
text
'
,
text
:
'
\
u200B
'
// Невидимый нулевой пробел
text
:
'
\
u200B
'
});
}
},
[
editor
,
getPos
]);
// Получаем текущую ширину редактора и доступное пространство
const
getEditorDimensions
=
()
=>
{
const
editorContent
=
editor
?.
options
?.
element
?.
closest
(
'
.atma-editor-content
'
);
...
...
@@ -115,7 +124,15 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select
useEffect
(()
=>
{
const
handleClickOutside
=
(
event
)
=>
{
if
(
wrapperRef
.
current
&&
!
wrapperRef
.
current
.
contains
(
event
.
target
)
&&
selected
)
{
editor
.
commands
.
setNodeSelection
(
getPos
());
try
{
const
pos
=
getPos
?.()
if
(
typeof
pos
===
'
number
'
)
{
editor
.
commands
.
setNodeSelection
(
pos
)
}
}
catch
(
e
)
{
console
.
warn
(
'
getPos() failed:
'
,
e
)
}
// editor.commands.setNodeSelection(getPos());
}
};
document
.
addEventListener
(
'
mousedown
'
,
handleClickOutside
);
...
...
@@ -192,7 +209,15 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select
e
.
stopPropagation
();
setIsResizing
(
true
);
editor
.
commands
.
setNodeSelection
(
getPos
());
try
{
const
pos
=
getPos
?.()
if
(
typeof
pos
===
'
number
'
)
{
editor
.
commands
.
setNodeSelection
(
pos
)
}
}
catch
(
e
)
{
console
.
warn
(
'
getPos() failed:
'
,
e
)
}
// editor.commands.setNodeSelection(getPos());
const
startWidth
=
node
.
attrs
.
width
||
imgRef
.
current
.
naturalWidth
;
const
startHeight
=
node
.
attrs
.
height
||
imgRef
.
current
.
naturalHeight
;
...
...
@@ -252,7 +277,15 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select
window
.
removeEventListener
(
'
mousemove
'
,
onMouseMove
);
window
.
removeEventListener
(
'
mouseup
'
,
onMouseUp
);
setIsResizing
(
false
);
editor
.
commands
.
setNodeSelection
(
getPos
());
try
{
const
pos
=
getPos
?.()
if
(
typeof
pos
===
'
number
'
)
{
editor
.
commands
.
setNodeSelection
(
pos
)
}
}
catch
(
e
)
{
console
.
warn
(
'
getPos() failed:
'
,
e
)
}
// editor.commands.setNodeSelection(getPos());
editor
.
commands
.
focus
();
};
...
...
@@ -335,7 +368,15 @@ const ResizableImageTemplate = ({ node, updateAttributes, editor, getPos, select
ref
=
{
wrapperRef
}
onClick
=
{
(
e
)
=>
{
e
.
stopPropagation
();
editor
.
commands
.
setNodeSelection
(
getPos
());
try
{
const
pos
=
getPos
?.()
if
(
typeof
pos
===
'
number
'
)
{
editor
.
commands
.
setNodeSelection
(
pos
)
}
}
catch
(
e
)
{
console
.
warn
(
'
getPos() failed:
'
,
e
)
}
// editor.commands.setNodeSelection(getPos());
}
}
contentEditable
=
{
false
}
data
-
image
-
wrapper
...
...
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