@@ -14,15 +14,23 @@ export const findEle = (id: string, instance?: MindElixirInstance) => {
1414}
1515
1616export const shapeTpc = function ( tpc : Topic , nodeObj : NodeObj ) {
17- tpc . textContent = nodeObj . topic
18-
1917 if ( nodeObj . style ) {
2018 tpc . style . color = nodeObj . style . color || ''
2119 tpc . style . background = nodeObj . style . background || ''
2220 tpc . style . fontSize = nodeObj . style . fontSize + 'px'
2321 tpc . style . fontWeight = nodeObj . style . fontWeight || 'normal'
2422 }
2523
24+ if ( nodeObj . branchColor ) {
25+ tpc . style . borderColor = nodeObj . branchColor
26+ }
27+
28+ // TODO
29+ // if (nodeObj.dangerouslySetInnerHTML) {
30+ // tpc.innerHTML = nodeObj.dangerouslySetInnerHTML
31+ // return
32+ // }
33+
2634 if ( nodeObj . image ) {
2735 const img = nodeObj . image
2836 if ( img . url && img . width && img . height ) {
@@ -35,6 +43,16 @@ export const shapeTpc = function (tpc: Topic, nodeObj: NodeObj) {
3543 } else {
3644 console . warn ( 'image url/width/height are required' )
3745 }
46+ } else if ( tpc . image ) {
47+ tpc . image = undefined
48+ }
49+
50+ {
51+ const textContainer = $d . createElement ( 'span' )
52+ textContainer . className = 'text'
53+ textContainer . textContent = nodeObj . topic
54+ tpc . appendChild ( textContainer )
55+ tpc . text = textContainer
3856 }
3957
4058 if ( nodeObj . hyperLink ) {
@@ -46,26 +64,27 @@ export const shapeTpc = function (tpc: Topic, nodeObj: NodeObj) {
4664 tpc . appendChild ( linkContainer )
4765 tpc . linkContainer = linkContainer
4866 } else if ( tpc . linkContainer ) {
49- tpc . linkContainer . remove ( )
50- tpc . linkContainer = null
67+ tpc . linkContainer = undefined
5168 }
69+
5270 if ( nodeObj . icons && nodeObj . icons . length ) {
5371 const iconsContainer = $d . createElement ( 'span' )
5472 iconsContainer . className = 'icons'
5573 iconsContainer . innerHTML = nodeObj . icons . map ( icon => `<span>${ encodeHTML ( icon ) } </span>` ) . join ( '' )
5674 tpc . appendChild ( iconsContainer )
5775 tpc . icons = iconsContainer
76+ } else if ( tpc . icons ) {
77+ tpc . icons = undefined
5878 }
79+
5980 if ( nodeObj . tags && nodeObj . tags . length ) {
6081 const tagsContainer = $d . createElement ( 'div' )
6182 tagsContainer . className = 'tags'
6283 tagsContainer . innerHTML = nodeObj . tags . map ( tag => `<span>${ encodeHTML ( tag ) } </span>` ) . join ( '' )
6384 tpc . appendChild ( tagsContainer )
6485 tpc . tags = tagsContainer
65- }
66-
67- if ( nodeObj . branchColor ) {
68- tpc . style . borderColor = nodeObj . branchColor
86+ } else if ( tpc . tags ) {
87+ tpc . tags = undefined
6988 }
7089}
7190
@@ -122,7 +141,7 @@ export const editTopic = function (this: MindElixirInstance, el: Topic) {
122141 console . time ( 'editTopic' )
123142 if ( ! el ) return
124143 const div = $d . createElement ( 'div' )
125- const origin = el . childNodes [ 0 ] . textContent as string
144+ const origin = el . text . textContent as string
126145 el . appendChild ( div )
127146 div . id = 'input-box'
128147 div . textContent = origin
@@ -161,7 +180,7 @@ export const editTopic = function (this: MindElixirInstance, el: Topic) {
161180 else node . topic = topic
162181 div . remove ( )
163182 if ( topic === origin ) return
164- el . childNodes [ 0 ] . textContent = node . topic
183+ el . text . textContent = node . topic
165184 this . linkDiv ( )
166185 this . bus . fire ( 'operation' , {
167186 name : 'finishEdit' ,
0 commit comments