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
1c8111c2
Commit
1c8111c2
authored
May 06, 2025
by
Яков
Browse files
update table insert
parent
b5e2da0e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/QEditor.jsx
View file @
1c8111c2
...
@@ -455,54 +455,6 @@ const QEditor = ({
...
@@ -455,54 +455,6 @@ const QEditor = ({
// }
// }
// }
// }
}
}
function
cleanWordHtml
(
html
)
{
return
html
// Удаляем MS Office специфичные теги
.
replace
(
/<
(
!|meta|link|style|o:
[^
>
]
+
)
>/gi
,
''
)
// Удаляем ненужные атрибуты
.
replace
(
/
\s(
class|style|lang
)
=
(
"|'
)[^
"'
]
*
(
"|'
)
/gi
,
''
)
// Заменяем MS теги на стандартные
.
replace
(
/<
(\/?)
v:
[^
>
]
+>/g
,
'
<$1span>
'
)
// Удаляем пустые параграфы
.
replace
(
/<p
[^
>
]
*>
(
|
\s)
*<
\/
p>/g
,
''
)
}
function
parseWordTable
(
html
)
{
const
doc
=
new
DOMParser
().
parseFromString
(
html
,
'
text/html
'
)
const
tables
=
doc
.
querySelectorAll
(
'
table
'
)
if
(
!
tables
.
length
)
return
null
const
table
=
tables
[
0
]
const
rows
=
[]
table
.
querySelectorAll
(
'
tr
'
).
forEach
(
tr
=>
{
const
cells
=
[]
tr
.
querySelectorAll
(
'
td, th
'
).
forEach
(
td
=>
{
cells
.
push
({
type
:
'
tableCell
'
,
content
:
[{
type
:
'
paragraph
'
,
content
:
td
.
textContent
?
[{
type
:
'
text
'
,
text
:
td
.
textContent
}]
:
[]
}]
})
})
rows
.
push
({
type
:
'
tableRow
'
,
content
:
cells
})
})
return
{
type
:
'
table
'
,
content
:
[
{
type
:
'
tableRow
'
,
content
:
rows
[
0
].
content
.
map
(()
=>
({
type
:
'
tableHeader
'
}))
},
...
rows
]
}
}
const
editor
=
useEditor
({
const
editor
=
useEditor
({
extensions
:
[
extensions
:
[
...
@@ -573,27 +525,6 @@ const QEditor = ({
...
@@ -573,27 +525,6 @@ const QEditor = ({
wrap
.
querySelectorAll
(
'
.atma-editor-toolbar-s
'
).
forEach
(
function
(
s
)
{
wrap
.
querySelectorAll
(
'
.atma-editor-toolbar-s
'
).
forEach
(
function
(
s
)
{
s
.
classList
.
remove
(
'
show
'
)
s
.
classList
.
remove
(
'
show
'
)
})
})
},
editorProps
:
{
handlePaste
:
(
view
,
event
)
=>
{
const
html
=
event
.
clipboardData
?.
getData
(
'
text/html
'
)
console
.
log
(
html
);
// Если вставляется таблица из Word
if
(
html
?.
includes
(
'
urn:schemas-microsoft-com:office:word
'
))
{
const
cleanedHtml
=
cleanWordHtml
(
html
)
// Функция очистки (см. ниже)
const
tr
=
view
.
state
.
tr
tr
.
replaceSelectionWith
(
view
.
state
.
schema
.
nodeFromJSON
({
type
:
'
table
'
,
content
:
parseWordTable
(
cleanedHtml
)
// Функция парсинга таблицы
}))
view
.
dispatch
(
tr
)
return
true
// Отменяем стандартную обработку
}
},
transformPastedHTML
(
html
)
{
return
cleanWordHtml
(
html
)
}
}
}
})
})
...
...
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