File tree Expand file tree Collapse file tree 4 files changed +25
-11
lines changed Expand file tree Collapse file tree 4 files changed +25
-11
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " mind-elixir" ,
3- "version" : " 0.19.7 " ,
3+ "version" : " 0.19.8 " ,
44 "description" : " Mind elixir is a free open source mind map core." ,
55 "main" : " dist/MindElixir.js" ,
66 "scripts" : {
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ interface Window {
1515
1616declare let window : Window
1717
18- const mind = new MindElixir ( {
18+ const options = {
1919 el : '#map' ,
2020 newTopicName : '子节点' ,
2121 direction : MindElixir . SIDE ,
@@ -59,16 +59,18 @@ const mind = new MindElixir({
5959 primaryLinkStyle : 1 ,
6060 primaryNodeVerticalGap : 15 , // 25
6161 primaryNodeHorizontalGap : 15 , // 65
62- } )
62+ }
63+
64+ const mind = new ( MindElixir as any ) ( options )
6365mind . init ( )
6466function sleep ( ) {
6567 return new Promise < void > ( ( res , rej ) => {
6668 setTimeout ( ( ) => res ( ) , 1000 )
6769 } )
6870}
6971console . log ( 'test E function' , E ( 'bd4313fbac40284b' ) )
70- const mind2 = new MindElixirLite ( {
71- el : '#map2' ,
72+ const mind2 = new ( MindElixirLite as any ) ( {
73+ el : document . querySelector ( '#map2' ) ,
7274 direction : 2 ,
7375 data : example2 ,
7476 draggable : false ,
Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ export interface MindElixirInstance {
111111
112112}
113113export interface Options {
114- el : string ,
114+ el : string | Element ,
115115 data : MindElixirData ,
116116 direction ?: number ,
117117 locale ?: string ,
@@ -147,8 +147,14 @@ function MindElixir(this: MindElixirInstance, {
147147 primaryNodeVerticalGap,
148148 mobileMenu,
149149} : Options ) {
150- const box = document . querySelector ( el ) as HTMLElement
151- if ( ! box ) return
150+ let box
151+ const elType = Object . prototype . toString . call ( el )
152+ if ( elType === '[object HTMLDivElement]' ) {
153+ box = el as HTMLElement
154+ } else if ( elType === '[object String]' ) {
155+ box = document . querySelector ( el as string ) as HTMLElement
156+ }
157+ if ( ! box ) return new Error ( 'MindElixir: el is not a valid element' )
152158 this . mindElixirBox = box
153159 this . nodeData = data . nodeData
154160 this . linkData = data . linkData || { }
Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ export interface MindElixirInstance {
153153 mobileMenu : boolean ,
154154}
155155export interface Options {
156- el : string ,
156+ el : string | Element ,
157157 data : MindElixirData ,
158158 direction ?: number ,
159159 locale ?: string ,
@@ -212,8 +212,14 @@ function MindElixir(this: MindElixirInstance, {
212212 primaryNodeVerticalGap,
213213 mobileMenu,
214214} : Options ) {
215- const box = document . querySelector ( el ) as HTMLElement
216- if ( ! box ) return
215+ let box
216+ const elType = Object . prototype . toString . call ( el )
217+ if ( elType === '[object HTMLDivElement]' ) {
218+ box = el as HTMLElement
219+ } else if ( elType === '[object String]' ) {
220+ box = document . querySelector ( el as string ) as HTMLElement
221+ }
222+ if ( ! box ) return new Error ( 'MindElixir: el is not a valid element' )
217223 this . mindElixirBox = box
218224 this . before = before || { }
219225 this . nodeData = data . nodeData
You can’t perform that action at this time.
0 commit comments