@@ -11,25 +11,6 @@ export function init(id, options) {
1111 const tree = { el, invoke, isVirtualize } ;
1212 Data . set ( id , tree )
1313
14- EventHandler . on ( el , 'mouseenter' , '.tree-content' , e => {
15- const ele = e . delegateTarget . parentNode
16- ele . classList . add ( 'hover' )
17- } )
18-
19- EventHandler . on ( el , 'mouseleave' , '.tree-content' , e => {
20- const ele = e . delegateTarget . parentNode
21- ele . classList . remove ( 'hover' )
22- } )
23-
24- EventHandler . on ( el , 'click' , '.tree-node' , e => {
25- const node = e . delegateTarget
26- const prev = node . previousElementSibling ;
27- const radio = prev . querySelector ( '[type="radio"]' )
28- if ( radio && radio . getAttribute ( 'disabled' ) !== 'disabled' ) {
29- radio . click ( ) ;
30- }
31- } )
32-
3314 EventHandler . on ( el , 'keydown' , '.tree-root' , e => {
3415 if ( e . key === 'ArrowDown' || e . key === 'ArrowUp' || e . key === 'ArrowLeft' || e . key === 'ArrowRight' ) {
3516 const v = el . getAttribute ( 'data-bb-keyboard' ) ;
@@ -41,33 +22,14 @@ export function init(id, options) {
4122 else if ( e . keyCode === 32 ) {
4223 const v = el . getAttribute ( 'data-bb-keyboard' ) ;
4324 if ( v === "true" ) {
44- const checkbox = el . querySelector ( ".active > .tree-content > .form-check > .form-check-input" ) ;
25+ const checkbox = el . querySelector ( ".active .form-check-input" ) ;
4526 if ( checkbox ) {
4627 e . preventDefault ( ) ;
4728 checkbox . click ( ) ;
4829 }
4930 }
5031 }
5132 } ) ;
52-
53- if ( isVirtualize ) {
54- EventHandler . on ( el , 'click' , '.form-check-input' , async e => {
55- const checkbox = e . delegateTarget ;
56- const state = checkbox . getAttribute ( 'data-bb-state' ) ;
57- if ( state ) {
58- const row = checkbox . closest ( '.tree-content' ) ;
59- const index = row . getAttribute ( 'data-bb-tree-view-index' ) ;
60-
61- const v = state === '1' ? 0 : 1 ;
62- await setChildrenState ( id , parseInt ( index ) , v ) ;
63- await setParentState ( id , parseInt ( index ) , v ) ;
64- const handler = setTimeout ( ( ) => {
65- checkbox . checked = v === 1 ;
66- clearTimeout ( handler ) ;
67- } , 0 ) ;
68- }
69- } ) ;
70- }
7133}
7234
7335export function scroll ( id , options ) {
@@ -114,13 +76,7 @@ export function setChildrenState(id, index, state) {
11476 if ( checkbox ) {
11577 checkbox . indeterminate = false ;
11678 checkbox . checked = state === 1 ;
117- checkbox . setAttribute ( 'data-bb-state' , state ) ;
118- if ( state === 1 ) {
119- checkbox . parentElement . classList . add ( 'is-checked' ) ;
120- }
121- else {
122- checkbox . parentElement . classList . remove ( 'is-checked' ) ;
123- }
79+ EventHandler . trigger ( checkbox , "statechange.bb.checkbox" , { state } ) ;
12480 }
12581 next = next . nextElementSibling ;
12682 }
@@ -151,7 +107,6 @@ export async function setParentState(id, index, state) {
151107 for ( let index = 0 ; index < parents . length ; index ++ ) {
152108 const checkbox = parents [ index ] . querySelector ( '.form-check-input' ) ;
153109 const result = results [ index ] ;
154- checkbox . setAttribute ( 'data-bb-state' , result ) ;
155110 checkbox . indeterminate = false ;
156111 if ( result === 0 ) {
157112 checkbox . checked = false ;
@@ -162,6 +117,7 @@ export async function setParentState(id, index, state) {
162117 else {
163118 checkbox . indeterminate = true ;
164119 }
120+ EventHandler . trigger ( checkbox , "statechange.bb.checkbox" , { state : result } ) ;
165121 }
166122 }
167123 }
@@ -173,14 +129,7 @@ export function dispose(id) {
173129 Data . remove ( id ) ;
174130
175131 if ( tree ) {
176- const { el, isVirtualize } = tree ;
177- EventHandler . off ( el , 'mouseenter' ) ;
178- EventHandler . off ( el , 'mouseleave' ) ;
179- EventHandler . off ( el , 'click' , '.tree-node' ) ;
132+ const { el } = tree ;
180133 EventHandler . off ( el , 'keyup' , '.tree-root' ) ;
181-
182- if ( isVirtualize ) {
183- EventHandler . off ( el , 'click' , '.form-check-input' ) ;
184- } ;
185134 }
186135}
0 commit comments