This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0

优化富文本编辑器和md编辑器的粘贴事件逻辑

old
yutent 2023-01-10 17:16:45 +08:00
parent 973fac0975
commit d0d09f0c9c
5 changed files with 36 additions and 24 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
*.min.js
*.min.css
.httpserver
index.html
.vscode
node_modules/

View File

@ -2,7 +2,7 @@ jsxBracketSameLine: true
jsxSingleQuote: true
semi: false
singleQuote: true
printWidth: 100
printWidth: 80
useTabs: false
tabWidth: 2
trailingComma: none

View File

@ -1,6 +1,6 @@
{
"name": "@bytedo/wcui",
"version": "1.0.6",
"version": "1.0.7",
"type": "module",
"description": "基于wc开发的一套UI库, 面向未来, 面向electron",
"scripts": {

View File

@ -582,13 +582,33 @@ export default class Editor {
var txt = ev.clipboardData.getData('text/plain')
var items = ev.clipboardData.items
// 先文件判断, 避免右键单击复制图片时, 当成html处理
if (items && items.length) {
let blob = null
for (let it of items) {
if (it.type.indexOf('image') > -1) {
blob = it.getAsFile()
}
}
if (blob) {
return this._handleImage(blob)
}
}
if (html) {
html = html
.replace(/\t/g, ' ')
.replace(/<\/?(meta|link|script)[^>]*?>/g, '')
.replace(/<!--[\w\W]*?-->/g, '')
.replace(/<a[^>]*? href\s?=\s?["']?([^"']*)["']?[^>]*?>/g, '<a href="$1">')
.replace(/<img[^>]*? src\s?=\s?["']?([^"']*)["']?[^>]*?>/g, '<img src="$1">')
.replace(
/<a[^>]*? href\s?=\s?["']?([^"']*)["']?[^>]*?>/g,
'<a href="$1">'
)
.replace(
/<img[^>]*? src\s?=\s?["']?([^"']*)["']?[^>]*?>/g,
'<img src="$1">'
)
.replace(/<(?!a|img)([\w\-]+)[^>]*>/g, '<$1>')
.replace(/<xml[^>]*?>[\w\W]*?<\/xml>/g, '')
.replace(/<style>[\w\W]*?<\/style>/g, '')
@ -599,16 +619,6 @@ export default class Editor {
if (txt) {
return this.exec('insertText', txt)
}
if (items && items.length) {
let blob = null
for (let it of items) {
if (it.type.indexOf('image') > -1) {
blob = it.getAsFile()
}
}
this._handleImage(blob)
}
})
this.__observer = new MutationObserver(_ => {

View File

@ -841,7 +841,7 @@ export default class Meditor {
ev.preventDefault()
wrap = wrap
.split('\n')
.map(function(it) {
.map(function (it) {
return ev.shiftKey ? it.replace(/^\s\s/, '') : ' ' + it
})
.join('\n')
@ -956,15 +956,6 @@ export default class Meditor {
return
}
if (html) {
html = html2md(html)
return this.insert(html)
}
if (txt) {
return this.insert(txt)
}
if (items && items.length) {
let file = null
@ -978,8 +969,18 @@ export default class Meditor {
} else {
this._handleUpload(file, '')
}
return
}
}
if (html) {
html = html2md(html)
return this.insert(html)
}
if (txt) {
return this.insert(txt)
}
})
this._clickFn = $.bind(this.__TOOLBAR__, 'click', ev => {