Feat:自定义处理剪贴板函数支持返回Promise实例

This commit is contained in:
wanglin2 2023-08-13 09:49:29 +08:00
parent 726ebc5e88
commit 2a8b71497f
3 changed files with 25 additions and 14 deletions

View File

@ -150,5 +150,6 @@ export const defaultOpt = {
}
}
*/
// 如果你的处理逻辑存在异步逻辑也可以返回一个promise
customHandleClipboardText: null
}

View File

@ -12,7 +12,8 @@ import {
simpleDeepClone,
walk,
bfsWalk,
loadImage
loadImage,
isUndef
} from '../../utils'
import { shapeList } from './node/Shape'
import { lineStyleProps } from '../../themes/default'
@ -668,14 +669,23 @@ class Render {
if (text) {
// 判断粘贴的是否是simple-mind-map的数据
let smmData = null
let useDefault = true
// 用户自定义处理
if (this.mindMap.opt.customHandleClipboardText) {
const res = this.mindMap.opt.customHandleClipboardText(text)
if (typeof res === 'object' && res.simpleMindMap) {
smmData = res.data
} else {
text = String(res)
}
} else {
try {
const res = await this.mindMap.opt.customHandleClipboardText(text)
if (!isUndef(res)) {
useDefault = false
if (typeof res === 'object' && res.simpleMindMap) {
smmData = res.data
} else {
text = String(res)
}
}
} catch (error) {}
}
// 默认处理
if (useDefault) {
try {
const parsedData = JSON.parse(text)
if (parsedData && parsedData.simpleMindMap) {

View File

@ -64,13 +64,13 @@ const transformXmind = async (content, files) => {
}
// 图片
if (node.image && /\.(jpg|jpeg|png|gif|webp)$/.test(node.image.src)) {
// 处理异步逻辑
let resolve = null
let promise = new Promise(_resolve => {
resolve = _resolve
})
waitLoadImageList.push(promise)
try {
// 处理异步逻辑
let resolve = null
let promise = new Promise(_resolve => {
resolve = _resolve
})
waitLoadImageList.push(promise)
// 读取图片
let imageType = /\.([^.]+)$/.exec(node.image.src)[1]
let imageBase64 =