@@ -14,7 +14,7 @@ MindMap.show = function (dotnetReference, containerId, mindMapOptions, mindMapDa
14
14
"version" : "1.0"
15
15
} ,
16
16
"format" : mindMapData . format ,
17
- "data" : mindMapData . data ,
17
+ "data" : mindMapData . data
18
18
} ;
19
19
20
20
const options = {
@@ -23,8 +23,8 @@ MindMap.show = function (dotnetReference, containerId, mindMapOptions, mindMapDa
23
23
theme : mindMapOptions . theme
24
24
}
25
25
26
- // Keep a reference to the javascript MindMap object
27
- instances [ containerId ] = window . jsMind . show ( options , mind ) ;
26
+ const mm = window . jsMind . show ( options , mind ) ; ;
27
+ mm [ "multiSelect" ] = mindMapOptions . multiSelect ;
28
28
29
29
// Call a callback to indicate that the MindMap is shown
30
30
dotnetReference . invokeMethodAsync ( "OnShowCallback" , { evt : "done" , node : "" , data : [ ] } ) ;
@@ -50,11 +50,50 @@ MindMap.show = function (dotnetReference, containerId, mindMapOptions, mindMapDa
50
50
}
51
51
}
52
52
53
- instances [ containerId ] . add_event_listener ( eventHandler ) ;
54
- } ;
53
+ // Custom
54
+ if ( mindMapOptions . multiSelect ) {
55
+ mm . selectedNodes = [ ] ;
56
+
57
+ const mousedown_handle = function ( e ) {
58
+ e . preventDefault ( ) ;
59
+
60
+ const element = e . target || event . srcElement ;
61
+ const id = this . view . get_binded_nodeid ( element ) ;
62
+ if ( id && element . tagName . toLowerCase ( ) === "jmnode" ) {
63
+ const node = mm . get_node ( id ) ;
64
+
65
+ // If already selected: remove from selected list and remove class
66
+ if ( mm . selectedNodes . includes ( id ) ) {
67
+ node . _data . view . element . className = node . _data . view . element . className . replace ( / \s * s e l e c t e d \b / g, "" ) ;
68
+
69
+ mm . selectedNodes . pop ( id ) ;
70
+ } else {
71
+ node . _data . view . element . className += " selected" ;
72
+
73
+ mm . selectedNodes . push ( id ) ;
74
+ }
75
+
76
+ //instances[containerId].select_clear();
77
+
78
+ //mm.selectedNodes.forEach(selectedId => {
79
+ // const selectedNode = instances[containerId].get_node(selectedId);
80
+ // selectedNode._data.view.element.className += " selected";
81
+ //});
82
+ }
83
+ }
84
+
85
+ mm . view . add_event ( mm , "mousedown" , mousedown_handle ) ;
86
+ }
87
+
88
+ mm . add_event_listener ( eventHandler ) ;
89
+
90
+ // Keep a reference to the javascript MindMap object
91
+ instances [ containerId ] = mm ;
92
+ }
55
93
56
94
MindMap . destroy = function ( containerId ) {
57
95
instances [ containerId ] = null ;
96
+ delete instances [ containerId ] ;
58
97
}
59
98
60
99
MindMap . addNode = function ( containerId , id , parentId , topic , data ) {
@@ -89,6 +128,26 @@ MindMap.selectNode = function (containerId, id) {
89
128
instances [ containerId ] . select_node ( id ) ;
90
129
}
91
130
131
+ MindMap . selectNodes = function ( containerId , nodes ) {
132
+ if ( instances [ containerId ] . multiSelect ) {
133
+ instances [ containerId ] . selectedNodes = [ ] ;
134
+
135
+ //instances[containerId].select_clear();
136
+
137
+ nodes . forEach ( node => {
138
+ const foundNode = instances [ containerId ] . get_node ( node . id ) ;
139
+ foundNode . _data . view . element . className += " selected" ;
140
+ //instances[containerId].clear_node_custom_style(foundNode);
141
+
142
+ instances [ containerId ] . selectedNodes . push ( node . id ) ;
143
+ } ) ;
144
+ }
145
+ }
146
+
147
+ MindMap . getNode = function ( containerId , id ) {
148
+ return mapNode ( instances [ containerId ] . get_node ( id ) ) ;
149
+ }
150
+
92
151
MindMap . clearSelect = function ( containerId ) {
93
152
instances [ containerId ] . select_clear ( ) ;
94
153
}
@@ -107,4 +166,16 @@ MindMap.enableEdit = function (containerId) {
107
166
108
167
MindMap . isEditable = function ( containerId ) {
109
168
return instances [ containerId ] . get_editable ( ) ;
169
+ }
170
+
171
+ mapNode = function ( node ) {
172
+ // Skip children property (TypeError: Converting circular structure to JSON)
173
+ return {
174
+ id : node . id ,
175
+ topic : node . topic ,
176
+ expanded : node . expanded ,
177
+ direction : node . direction ,
178
+ data : node . data ,
179
+ parentId : node . parentId
180
+ } ;
110
181
}
0 commit comments