@@ -53,14 +53,13 @@ const calcRange = function (nodes: Topic[]) {
5353 }
5454 }
5555 }
56+ if ( ! index ) throw new Error ( 'Can not select root node.' )
5657 const range = parentChains . map ( chain => chain [ index - 1 ] . index ) . sort ( )
5758 const min = range [ 0 ] || 0
5859 const max = range [ range . length - 1 ] || 0
5960 const parent = parentChains [ 0 ] [ index - 1 ] . node
6061 if ( parent . root ) throw new Error ( 'Please select nodes in the same main topic.' )
6162
62- // const start = parent.children![min].id
63- // const end = parent.children![max].id
6463 return {
6564 parent : parent . id ,
6665 start : min ,
@@ -100,12 +99,24 @@ const createText = function (string: string, x: number, y: number, anchor: 'star
10099
101100const getWrapper = ( id : string ) => findEle ( id ) . parentElement . parentElement
102101
102+ const getDirection = function ( { parent, start } : Summary ) {
103+ const parentEl = findEle ( parent )
104+ const parentObj = parentEl . nodeObj
105+ let side : 'lhs' | 'rls'
106+ if ( parentObj . root === true ) {
107+ side = findEle ( parentObj . children ! [ start ] . id ) . closest ( 'me-main' ) ?. className as 'lhs' | 'rls'
108+ } else {
109+ side = parentEl . closest ( 'me-main' ) ?. className as 'lhs' | 'rls'
110+ }
111+ return side
112+ }
113+
103114const drawSummary = function ( mei : MindElixirInstance , summary : Summary ) {
104115 const { id, text : summaryText , parent, start, end } = summary
105116 const container = mei . nodes
106117 const parentEl = findEle ( parent )
107- const side = parentEl . closest ( 'me-main' ) ?. className as 'lhs' | 'rls'
108118 const parentObj = parentEl . nodeObj
119+ const side = getDirection ( summary )
109120 let left = Infinity
110121 let right = 0
111122 let startTop = 0
@@ -200,10 +211,6 @@ export const renderSummary = function (this: MindElixirInstance) {
200211 this . nodes . insertAdjacentElement ( 'beforeend' , this . summarySvg )
201212}
202213
203- const getDirection = function ( id : string ) {
204- return findEle ( id ) . closest ( 'me-main' ) ?. className as 'lhs' | 'rls'
205- }
206-
207214export const editSummary = function ( this : MindElixirInstance , el : SummarySvgGroup ) {
208215 console . time ( 'editSummary' )
209216 if ( ! el ) return
@@ -218,7 +225,7 @@ export const editSummary = function (this: MindElixirInstance, el: SummarySvgGro
218225 const l = textEl . getAttribute ( 'x' ) + 'px'
219226 const t = textEl . getAttribute ( 'y' ) + 'px'
220227 div . style . cssText = `min-width:${ 100 - 8 } px;position:absolute;left:${ l } ;top:${ t } ;`
221- if ( getDirection ( el . summaryObj . parent ) === 'lhs' ) div . style . cssText += 'transform: translate(-100%, -100%);'
228+ if ( getDirection ( el . summaryObj ) === 'lhs' ) div . style . cssText += 'transform: translate(-100%, -100%);'
222229 else div . style . cssText += 'transform: translate(0, -100%);'
223230 div . focus ( )
224231
0 commit comments