universal_table/app/assets/javascripts/mind_map/utils/custom.overrides.js

75 lines
2.2 KiB
JavaScript

import { util } from '../jsmind/jsmind.util.js'
import { Mind } from '../jsmind/jsmind.mind.js'
import { ViewProvider } from '../jsmind/jsmind.view_provider.js'
import jsMind from '../jsmind/jsmind.js'
ViewProvider.prototype.edit_node_end = function () {
if (this.editing_node != null) {
var node = this.editing_node
this.editing_node = null
var view_data = node._data.view
var element = view_data.element
// 客製化修改:顯示文字由 node.data 控制
// Customization: Display text is controlled by node.data
var topic = node.data.text
element.style.zIndex = 'auto'
element.removeChild(this.e_editor)
if (util.text.is_empty(topic) || node.topic === topic) {
this.render_node(element, node)
} else {
this.jm.update_node(node.id, topic)
}
}
this.e_panel.focus()
}
ViewProvider.prototype.select_node = function (node) {
if (!!this.selected_node) {
var element = this.selected_node._data.view.element
element.className = element.className.replace(/\s*selected\b/i, '')
this.restore_selected_node_custom_style(this.selected_node)
}
if (!!node) {
this.selected_node = node
node._data.view.element.className += ' selected'
// 客製化修改:不清除自定義樣式
// Customization: Do not clear custom styles
// this.clear_selected_node_custom_style(node)
}
}
const originalAddNode = Mind.prototype.add_node
Mind.prototype.add_node = function (
parent_node,
node_id,
topic,
data = undefined,
direction,
expanded,
idx
) {
if (data == undefined) {
data = {}
for (let style of [
'leading-line-color',
'background-color',
'foreground-color',
]) {
if (data[style] == undefined && parent_node.data?.[style]) {
data[style] = parent_node.data[style]
}
}
}
arguments[3] = data
return originalAddNode.apply(this, arguments)
}
const originalMousedownHandle = jsMind.prototype.mousedown_handle
jsMind.prototype.mousedown_handle = function (e) {
if (e.button !== 0) return
return originalMousedownHandle.apply(this, arguments)
}