diff --git a/index.html b/index.html index 32e46b1b..af9a7dd7 100644 --- a/index.html +++ b/index.html @@ -1 +1 @@ -一个简单的web思维导图实现
\ No newline at end of file +一个简单的web思维导图实现
\ No newline at end of file diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js index d3cdbe74..107ea996 100644 --- a/simple-mind-map/index.js +++ b/simple-mind-map/index.js @@ -281,6 +281,7 @@ class MindMap { layout = CONSTANTS.LAYOUT.LOGICAL_STRUCTURE } this.opt.layout = layout + this.view.reset() this.renderer.setLayout() this.render() } diff --git a/simple-mind-map/package.json b/simple-mind-map/package.json index 783d8696..311495d0 100644 --- a/simple-mind-map/package.json +++ b/simple-mind-map/package.json @@ -1,6 +1,6 @@ { "name": "simple-mind-map", - "version": "0.5.5", + "version": "0.5.5-fix.1", "description": "一个简单的web在线思维导图", "authors": [ { diff --git a/simple-mind-map/src/Select.js b/simple-mind-map/src/Select.js index 98a53c0a..a8c847c9 100644 --- a/simple-mind-map/src/Select.js +++ b/simple-mind-map/src/Select.js @@ -17,7 +17,7 @@ class Select { // 绑定事件 bindEvent() { - this.checkInNodes = throttle(this.checkInNodes, 500, this) + this.checkInNodes = throttle(this.checkInNodes, 300, this) this.mindMap.on('mousedown', e => { if (this.mindMap.opt.readonly) { return @@ -146,22 +146,26 @@ class Select { let bottom = (top + height) * scaleY + translateY left = left * scaleX + translateX top = top * scaleY + translateY - if (left >= minx && right <= maxx && top >= miny && bottom <= maxy) { - this.mindMap.batchExecution.push('activeNode' + node.uid, () => { + if ((left >= minx && left <= maxx || + right >= minx && right <= maxx) && + (top >= miny && top <= maxy || + bottom >= miny && bottom <= maxy) + ) { + // this.mindMap.batchExecution.push('activeNode' + node.uid, () => { if (node.nodeData.data.isActive) { return } this.mindMap.renderer.setNodeActive(node, true) this.mindMap.renderer.addActiveNode(node) - }) + // }) } else if (node.nodeData.data.isActive) { - this.mindMap.batchExecution.push('activeNode' + node.uid, () => { + // this.mindMap.batchExecution.push('activeNode' + node.uid, () => { if (!node.nodeData.data.isActive) { return } this.mindMap.renderer.setNodeActive(node, false) this.mindMap.renderer.removeActiveNode(node) - }) + // }) } }) } diff --git a/simple-mind-map/src/TextEdit.js b/simple-mind-map/src/TextEdit.js index f2f9330b..b371f658 100644 --- a/simple-mind-map/src/TextEdit.js +++ b/simple-mind-map/src/TextEdit.js @@ -1,4 +1,4 @@ -import { getStrWithBrFromHtml } from './utils' +import { getStrWithBrFromHtml, checkNodeOuter } from './utils' // 节点文字编辑类 export default class TextEdit { @@ -60,6 +60,8 @@ export default class TextEdit { // 显示文本编辑框 show(node) { + let { offsetLeft, offsetTop } = checkNodeOuter(this.mindMap, node) + this.mindMap.view.translateXY(offsetLeft, offsetTop) let rect = node._textData.node.node.getBoundingClientRect() if (this.mindMap.richText) { this.mindMap.richText.showEditText(node, rect) diff --git a/simple-mind-map/src/View.js b/simple-mind-map/src/View.js index 16f160bc..ffe2599f 100644 --- a/simple-mind-map/src/View.js +++ b/simple-mind-map/src/View.js @@ -124,6 +124,13 @@ class View { } } + // 平移x,y方向 + translateXY(x, y) { + this.x += x + this.y += y + this.transform() + } + // 平移x方向 translateX(step) { this.x += step @@ -160,10 +167,14 @@ class View { // 恢复 reset() { + let scaleChange = this.scale !== 1 this.scale = 1 this.x = 0 this.y = 0 this.transform() + if (scaleChange) { + this.mindMap.emit('scale', this.scale) + } } // 缩小 diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index 3dade497..476cb974 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -302,4 +302,34 @@ export const nextTick = function (fn, ctx) { pending = true timerFunc(handle, 0) } +} + +// 检查节点是否超出画布 +export const checkNodeOuter = (mindMap, node) => { + let elRect = mindMap.elRect + let { scaleX, scaleY, translateX, translateY } = mindMap.draw.transform() + let { left, top, width, height } = node + let right = (left + width) * scaleX + translateX + let bottom = (top + height) * scaleY + translateY + left = left * scaleX + translateX + top = top * scaleY + translateY + let offsetLeft = 0 + let offsetTop = 0 + if (left < 0) { + offsetLeft = -left + } + if (right > elRect.width) { + offsetLeft = -(right - elRect.width) + } + if (top < 0) { + offsetTop = -top + } + if (bottom > elRect.height) { + offsetTop = -(bottom - elRect.height) + } + return { + isOuter: offsetLeft !== 0 || offsetTop !== 0, + offsetLeft, + offsetTop + } } \ No newline at end of file diff --git a/web/src/pages/Doc/en/changelog/index.md b/web/src/pages/Doc/en/changelog/index.md index 50b58823..f4f6088a 100644 --- a/web/src/pages/Doc/en/changelog/index.md +++ b/web/src/pages/Doc/en/changelog/index.md @@ -1,5 +1,11 @@ # Changelog +## 0.5.5-fix.1 + +Fix: 1.Fix the issue where the edit box is also outside the canvas when editing nodes outside the canvas. 2.After modifying the structure, reset the transformation to prevent the problem of sudden position changes during the first drag after switching the structure during scaling. + +optimization: 1.When multiple nodes are selected, as long as there is a cross between the node and the selection area, it is considered selected. + ## 0.5.5 New: 1.Supports configuring the padding when exporting to PNG, SVG, or PDF. 2.Support the configuration of z-index for node text editing boxes and node comment floating layer elements. 3.Support clicking on areas outside the canvas to end node editing status. diff --git a/web/src/pages/Doc/en/changelog/index.vue b/web/src/pages/Doc/en/changelog/index.vue index 0ee79ab6..c7e18164 100644 --- a/web/src/pages/Doc/en/changelog/index.vue +++ b/web/src/pages/Doc/en/changelog/index.vue @@ -1,6 +1,9 @@