@@ -23,43 +23,40 @@ export class NgtSelect {
2323 const elementRef = inject < ElementRef < Group | Mesh > > ( ElementRef ) ;
2424 const selection = inject ( NgtSelection ) ;
2525
26- effect (
27- ( onCleanup ) => {
28- const selectionEnabled = selection . enabled ( ) ;
29- if ( ! selectionEnabled ) return ;
30-
31- const enabled = this . enabled ( ) ;
32- if ( ! enabled ) return ;
33-
34- const host = elementRef . nativeElement ;
35- if ( ! host ) return ;
36-
37- const localState = getLocalState ( host ) ;
38- if ( ! localState ) return ;
39-
40- // ngt-mesh[ngtSelect]
41- if ( host . type === 'Mesh' ) {
42- selection . update ( ( prev ) => [ ...prev , host ] ) ;
43- onCleanup ( ( ) => selection . update ( ( prev ) => prev . filter ( ( el ) => el !== host ) ) ) ;
44- return ;
45- }
46-
47- const [ collection ] = [ untracked ( selection . selected ) , localState . objects ( ) ] ;
48- let changed = false ;
49- const current : Object3D [ ] = [ ] ;
50- host . traverse ( ( child ) => {
51- child . type === 'Mesh' && current . push ( child ) ;
52- if ( collection . indexOf ( child ) === - 1 ) changed = true ;
53- } ) ;
54-
55- if ( ! changed ) return ;
56-
57- selection . update ( ( prev ) => [ ...prev , ...current ] ) ;
58- onCleanup ( ( ) => {
59- selection . update ( ( prev ) => prev . filter ( ( el ) => ! current . includes ( el as Object3D ) ) ) ;
60- } ) ;
61- } ,
62- { allowSignalWrites : true } ,
63- ) ;
26+ effect ( ( onCleanup ) => {
27+ const selectionEnabled = selection . enabled ( ) ;
28+ if ( ! selectionEnabled ) return ;
29+
30+ const enabled = this . enabled ( ) ;
31+ if ( ! enabled ) return ;
32+
33+ const host = elementRef . nativeElement ;
34+ if ( ! host ) return ;
35+
36+ const localState = getLocalState ( host ) ;
37+ if ( ! localState ) return ;
38+
39+ // ngt-mesh[ngtSelect]
40+ if ( host . type === 'Mesh' ) {
41+ selection . update ( ( prev ) => [ ...prev , host ] ) ;
42+ onCleanup ( ( ) => selection . update ( ( prev ) => prev . filter ( ( el ) => el !== host ) ) ) ;
43+ return ;
44+ }
45+
46+ const [ collection ] = [ untracked ( selection . selected ) , localState . objects ( ) ] ;
47+ let changed = false ;
48+ const current : Object3D [ ] = [ ] ;
49+ host . traverse ( ( child ) => {
50+ child . type === 'Mesh' && current . push ( child ) ;
51+ if ( collection . indexOf ( child ) === - 1 ) changed = true ;
52+ } ) ;
53+
54+ if ( ! changed ) return ;
55+
56+ selection . update ( ( prev ) => [ ...prev , ...current ] ) ;
57+ onCleanup ( ( ) => {
58+ selection . update ( ( prev ) => prev . filter ( ( el ) => ! current . includes ( el as Object3D ) ) ) ;
59+ } ) ;
60+ } ) ;
6461 }
6562}
0 commit comments