11import type { TextBoxInstance } from '@js/ui/text_box' ;
2- import type { ReadonlySignal } from '@preact/signals-core' ;
3- import { computed } from '@preact/signals-core' ;
2+ import type { Signal } from '@preact/signals-core' ;
3+ import { effect , signal } from '@preact/signals-core' ;
44import { ToolbarController } from '@ts/grids/new/grid_core/toolbar/controller' ;
55
66import { OptionsController } from '../options_controller/options_controller' ;
77import { SearchController } from './controller' ;
88import { SearchUIController } from './controller_ui' ;
9- import type { SearchFieldProps } from './types' ;
109import { addSearchTextBox } from './utils' ;
1110
1211export class SearchView {
@@ -17,36 +16,40 @@ export class SearchView {
1716 SearchController ,
1817 ] as const ;
1918
20- private searchTextBox : TextBoxInstance | null = null ;
19+ private readonly searchTextBox : Signal < null | TextBoxInstance > = signal ( null ) ;
2120
2221 constructor (
2322 private readonly options : OptionsController ,
2423 private readonly toolbarController : ToolbarController ,
2524 private readonly searchUIController : SearchUIController ,
2625 private readonly searchController : SearchController ,
2726 ) {
27+ const toolbarItem = addSearchTextBox (
28+ {
29+ placeholder : this . searchController . searchPlaceholder . value ,
30+ value : this . searchController . searchTextOption . value ,
31+ width : this . searchController . searchWidth . value ,
32+ onValueChanged : ( text ) : void => {
33+ this . searchController . updateSearchText ( text ) ;
34+ } ,
35+ } ,
36+ ( component ) => {
37+ this . searchTextBox . value = component ;
38+ } ,
39+ ) ;
2840 this . toolbarController . addDefaultItem (
29- computed ( ( ) => addSearchTextBox (
30- this . getProps ( ) . value ,
31- ( component ) => { this . searchTextBox = component ; } ,
32- ) ) ,
41+ signal ( toolbarItem ) ,
3342 this . options . oneWay ( 'searchPanel.visible' ) ,
3443 ) ;
3544
36- this . searchUIController . registerCallback ( 'focusSearchTextBox' , ( ) => {
37- this . searchTextBox ?. focus ( ) ;
45+ effect ( ( ) => {
46+ this . searchTextBox . value ?. option ( 'value' , this . searchController . searchTextOption . value ) ;
47+ this . searchTextBox . value ?. option ( 'placeholder' , this . searchController . searchPlaceholder . value ) ;
48+ this . searchTextBox . value ?. option ( 'width' , this . searchController . searchWidth . value ) ;
3849 } ) ;
39- }
4050
41- protected getProps ( ) : ReadonlySignal < SearchFieldProps > {
42- return computed ( ( ) => ( {
43- placeholder : this . options . oneWay ( 'searchPanel.placeholder' ) . value ,
44- // TODO: resolve update cycle: editor - option - editor
45- // value: this.searchController.searchTextOption.value,
46- width : this . options . oneWay ( 'searchPanel.width' ) . value ,
47- onValueChanged : ( text ) : void => {
48- this . searchController . updateSearchText ( text ) ;
49- } ,
50- } ) ) ;
51+ this . searchUIController . registerCallback ( 'focusSearchTextBox' , ( ) => {
52+ this . searchTextBox . value ?. focus ( ) ;
53+ } ) ;
5154 }
5255}
0 commit comments