Feat:修改复制粘贴实现方式,去除创建隐藏输入框,支持跨浏览器粘贴思维导图数据

This commit is contained in:
wanglin2 2023-08-12 10:57:51 +08:00
parent c6a3f4ac7b
commit 5745e4567b
2 changed files with 53 additions and 9 deletions

View File

@ -1,11 +1,11 @@
{ {
"name": "simple-mind-map", "name": "simple-mind-map",
"version": "0.6.12", "version": "0.6.13",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"version": "0.6.12", "version": "0.6.13",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@svgdotjs/svg.js": "^3.0.16", "@svgdotjs/svg.js": "^3.0.16",

View File

@ -444,7 +444,12 @@ class Render {
} }
// 插入同级节点,多个节点只会操作第一个节点 // 插入同级节点,多个节点只会操作第一个节点
insertNode(openEdit = true, appointNodes = [], appointData = null) { insertNode(
openEdit = true,
appointNodes = [],
appointData = null,
appointChildren = []
) {
appointNodes = this.formatAppointNodes(appointNodes) appointNodes = this.formatAppointNodes(appointNodes)
if (this.activeNodeList.length <= 0 && appointNodes.length <= 0) { if (this.activeNodeList.length <= 0 && appointNodes.length <= 0) {
return return
@ -480,14 +485,19 @@ class Render {
resetRichText: isRichText, resetRichText: isRichText,
...(appointData || {}) ...(appointData || {})
}, },
children: [] children: [...appointChildren]
}) })
this.mindMap.render() this.mindMap.render()
} }
} }
// 插入子节点 // 插入子节点
insertChildNode(openEdit = true, appointNodes = [], appointData = null) { insertChildNode(
openEdit = true,
appointNodes = [],
appointData = null,
appointChildren = []
) {
appointNodes = this.formatAppointNodes(appointNodes) appointNodes = this.formatAppointNodes(appointNodes)
if (this.activeNodeList.length <= 0 && appointNodes.length <= 0) { if (this.activeNodeList.length <= 0 && appointNodes.length <= 0) {
return return
@ -518,7 +528,7 @@ class Render {
resetRichText: isRichText, resetRichText: isRichText,
...(appointData || {}) ...(appointData || {})
}, },
children: [] children: [...appointChildren]
}) })
// 插入子节点时自动展开子节点 // 插入子节点时自动展开子节点
node.nodeData.data.expand = true node.nodeData.data.expand = true
@ -586,15 +596,29 @@ class Render {
// 复制节点 // 复制节点
copy() { copy() {
this.beingCopyData = this.copyNode() this.beingCopyData = this.copyNode()
this.setCoptyDataToClipboard(this.beingCopyData)
} }
// 剪切节点 // 剪切节点
cut() { cut() {
this.mindMap.execCommand('CUT_NODE', copyData => { this.mindMap.execCommand('CUT_NODE', copyData => {
this.beingCopyData = copyData this.beingCopyData = copyData
this.setCoptyDataToClipboard(copyData)
}) })
} }
// 将粘贴或剪切的数据设置到用户剪切板中
setCoptyDataToClipboard(data) {
if (navigator.clipboard) {
navigator.clipboard.writeText(
JSON.stringify({
simpleMindMap: true,
data
})
)
}
}
// 粘贴节点 // 粘贴节点
paste() { paste() {
if (this.beingCopyData) { if (this.beingCopyData) {
@ -642,9 +666,29 @@ class Render {
if (this.currentBeingPasteType === CONSTANTS.PASTE_TYPE.CLIP_BOARD) { if (this.currentBeingPasteType === CONSTANTS.PASTE_TYPE.CLIP_BOARD) {
// 存在文本,则创建子节点 // 存在文本,则创建子节点
if (text) { if (text) {
this.mindMap.execCommand('INSERT_CHILD_NODE', false, [], { // 判断粘贴的是否是simple-mind-map的数据
text let smmData = null
}) try {
const parsedData = JSON.parse(text)
if (parsedData && parsedData.simpleMindMap) {
smmData = parsedData.data
}
} catch (error) {}
if (smmData) {
this.mindMap.execCommand(
'INSERT_CHILD_NODE',
false,
[],
{
...smmData.data
},
[...smmData.children]
)
} else {
this.mindMap.execCommand('INSERT_CHILD_NODE', false, [], {
text
})
}
} }
// 存在图片,则添加到当前激活节点 // 存在图片,则添加到当前激活节点
if (img) { if (img) {