-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Describe the bug / 问题描述
自定义drawEditorShape 方法是绑定的监听事件无法触发到 handleRestart绑定到window也无法触发
// 创建一个html 的文本输入框
getEditorStyle(attributes) {
const { color = '#000000', size } = attributes
const node = this.nodeData[0]
if (!node?.states?.includes('selected')) return false
const isRoot = node.depth === 0
const [width, height] = size
return {
size: size, // 宽高与节点一致,确保完全覆盖
dx: -width / 2,
dy: -height / 2,
// 自定义 HTML 内容,按需求调整样式
innerHTML: `
<div style="
width: ${width}px;
height:${height}px;
background: ${color};
text-align: center;
border-radius: 8px;
padding:8px 12px"
contenteditable="true"
onclick="handleRestart('${node}')">
<span style=" font-size:${isRoot ? 24 : 16}px; font-weight: ${node?.depth > 1 ? 400 : 600};">
${node.data.text}
</span>
</div>
`,
// 层级:设为 10 确保在节点其他元素之上
zIndex: 10,
}
}
drawEditorShape(attributes, container) {
const editorStyle: any = this.getEditorStyle(attributes)
const { x, y, width = 0, height = 0 } = editorStyle
const bounds = this.upsert('key-container', Rect, { x, y, width, height, opacity: 0 }, container)!
const btn = this.upsert('editor', GHTML, editorStyle, bounds)
this.forwardEvent(btn, CommonEvent.CLICK, (event) => {
console.log('editor', event)
event.stopPropagation()
this.context.graph.emit(TreeEvent.EDIT_NODE, {
id: this.id,
direction: attributes.direction,
})
})
}
Reproduction link / 复现链接
No response
Steps to Reproduce the Bug or Issue / 重现步骤
No response
Version / 版本
🆕 5.x
OS / 操作系统
- macOS
- Windows
- Linux
- Others / 其他
Browser / 浏览器
- Chrome
- Edge
- Firefox
- Safari (Limited support / 有限支持)
- IE (Nonsupport / 不支持)
- Others / 其他
Metadata
Metadata
Assignees
Labels
No labels