Feat:粘贴带换行的文本支持控制是否按换行分割节点
This commit is contained in:
parent
93a56ef4ee
commit
7bc666be36
@ -214,5 +214,8 @@ export const defaultOpt = {
|
|||||||
// false:即创建关联线和激活关联线时处于最顶层,其他情况下处于节点下方
|
// false:即创建关联线和激活关联线时处于最顶层,其他情况下处于节点下方
|
||||||
associativeLineIsAlwaysAboveNode: true,
|
associativeLineIsAlwaysAboveNode: true,
|
||||||
// 插入概要的默认文本
|
// 插入概要的默认文本
|
||||||
defaultGeneralizationText: '概要'
|
defaultGeneralizationText: '概要',
|
||||||
|
// 粘贴文本的方式创建新节点时,控制是否按换行自动分割节点,即如果存在换行,那么会根据换行创建多个节点,否则只会创建一个节点
|
||||||
|
// 可以传递一个函数,返回promise,resolve代表根据换行分割,reject代表忽略换行
|
||||||
|
handleIsSplitByWrapOnPasteCreateNewNode: null
|
||||||
}
|
}
|
||||||
|
|||||||
@ -819,7 +819,8 @@ class Render {
|
|||||||
|
|
||||||
// 粘贴事件
|
// 粘贴事件
|
||||||
async onPaste() {
|
async onPaste() {
|
||||||
const { errorHandler } = this.mindMap.opt
|
const { errorHandler, handleIsSplitByWrapOnPasteCreateNewNode } =
|
||||||
|
this.mindMap.opt
|
||||||
// 读取剪贴板的文字和图片
|
// 读取剪贴板的文字和图片
|
||||||
let text = null
|
let text = null
|
||||||
let img = null
|
let img = null
|
||||||
@ -884,9 +885,36 @@ class Render {
|
|||||||
Array.isArray(smmData) ? smmData : [smmData]
|
Array.isArray(smmData) ? smmData : [smmData]
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
this.mindMap.execCommand('INSERT_CHILD_NODE', false, [], {
|
const textArr = text.split(/\r?\n|(?<!\n)\r/g).filter(item => {
|
||||||
text
|
return !!item
|
||||||
})
|
})
|
||||||
|
// 判断是否需要根据换行自动分割节点
|
||||||
|
if (textArr.length > 1 && handleIsSplitByWrapOnPasteCreateNewNode) {
|
||||||
|
handleIsSplitByWrapOnPasteCreateNewNode()
|
||||||
|
.then(() => {
|
||||||
|
this.mindMap.execCommand(
|
||||||
|
'INSERT_MULTI_CHILD_NODE',
|
||||||
|
[],
|
||||||
|
textArr.map(item => {
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
text: item
|
||||||
|
},
|
||||||
|
children: []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.mindMap.execCommand('INSERT_CHILD_NODE', false, [], {
|
||||||
|
text
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.mindMap.execCommand('INSERT_CHILD_NODE', false, [], {
|
||||||
|
text
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 存在图片,则添加到当前激活节点
|
// 存在图片,则添加到当前激活节点
|
||||||
|
|||||||
@ -96,7 +96,7 @@ MindMap.usePlugin(MiniMap)
|
|||||||
.usePlugin(Painter)
|
.usePlugin(Painter)
|
||||||
.usePlugin(ScrollbarPlugin)
|
.usePlugin(ScrollbarPlugin)
|
||||||
.usePlugin(Formula)
|
.usePlugin(Formula)
|
||||||
// .usePlugin(Cooperate)// 协同插件
|
// .usePlugin(Cooperate)// 协同插件
|
||||||
|
|
||||||
// 注册自定义主题
|
// 注册自定义主题
|
||||||
customThemeList.forEach(item => {
|
customThemeList.forEach(item => {
|
||||||
@ -306,7 +306,14 @@ export default {
|
|||||||
useLeftKeySelectionRightKeyDrag: this.useLeftKeySelectionRightKeyDrag,
|
useLeftKeySelectionRightKeyDrag: this.useLeftKeySelectionRightKeyDrag,
|
||||||
customInnerElsAppendTo: null,
|
customInnerElsAppendTo: null,
|
||||||
enableAutoEnterTextEditWhenKeydown: true,
|
enableAutoEnterTextEditWhenKeydown: true,
|
||||||
customHandleClipboardText: handleClipboardText
|
customHandleClipboardText: handleClipboardText,
|
||||||
|
handleIsSplitByWrapOnPasteCreateNewNode: () => {
|
||||||
|
return this.$confirm('是否按换行自动分割节点?', '提示', {
|
||||||
|
confirmButtonText: '是',
|
||||||
|
cancelButtonText: '否',
|
||||||
|
type: 'warning'
|
||||||
|
})
|
||||||
|
}
|
||||||
// isUseCustomNodeContent: true,
|
// isUseCustomNodeContent: true,
|
||||||
// 示例1:组件里用到了router、store、i18n等实例化vue组件时需要用到的东西
|
// 示例1:组件里用到了router、store、i18n等实例化vue组件时需要用到的东西
|
||||||
// customCreateNodeContent: (node) => {
|
// customCreateNodeContent: (node) => {
|
||||||
@ -598,7 +605,10 @@ export default {
|
|||||||
color: ['#409EFF', '#67C23A', '#E6A23C', '#F56C6C', '#909399'][
|
color: ['#409EFF', '#67C23A', '#E6A23C', '#F56C6C', '#909399'][
|
||||||
Math.floor(Math.random() * 5)
|
Math.floor(Math.random() * 5)
|
||||||
],
|
],
|
||||||
avatar: Math.random() > 0.5 ? 'https://img0.baidu.com/it/u=4270674549,2416627993&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1696006800&t=4d32871d14a7224a4591d0c3c7a97311' : ''
|
avatar:
|
||||||
|
Math.random() > 0.5
|
||||||
|
? 'https://img0.baidu.com/it/u=4270674549,2416627993&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1696006800&t=4d32871d14a7224a4591d0c3c7a97311'
|
||||||
|
: ''
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user