forked from hyoo-ru/mam_mol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.view.ts
93 lines (71 loc) · 1.98 KB
/
select.view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
namespace $.$$ {
export class $mol_select extends $.$mol_select {
@ $mol_mem
filter_pattern( next? : string ) {
if( !this.focused() ) return ''
return next || ''
}
open() {
this.options_showed( true )
}
@ $mol_mem
options_showed( next = false ) {
this.focused()
return next
}
@ $mol_mem
options() {
return Object.keys( this.dictionary() ) as readonly string[]
}
@ $mol_mem
options_filtered() {
let options = this.options()
options = options.filter( $mol_match_text( this.filter_pattern() , ( id : string )=> [ this.option_label( id ) ] ) )
const index = options.indexOf( this.value() )
if( index >= 0 ) options = [ ... options.slice( 0 , index ) , ... options.slice( index + 1 ) ]
return options
}
option_label( id : string ) {
const value = this.dictionary()[ id ]
return value == null ? id : value
}
option_rows() {
if( this.options_filtered().length === 0 ) return [ this.No_options() ]
let options = this.options_filtered().map( ( option : string ) => this.Option_row( option ) )
return options
}
@ $mol_mem
option_focused( component? : $mol_view ) {
if( component == null ) {
for( let comp of this.nav_components() ) {
if( comp && comp.focused() ) return comp
}
return this.Filter()
}
if( this.options_showed() ) {
component.focused( true )
}
return component
}
event_select( id : string , event? : MouseEvent ) {
this.value( id )
this.focused( false )
}
nav_components() {
return [ this.Filter() , ... this.option_rows() ]
}
option_content_current() {
return this.option_content( this.value() )
}
trigger_content() {
return ( !this.value() && this.Filter() )
? [ this.Filter() ]
: [ ... this.option_content_current() , this.Trigger_icon() ]
}
menu_content() {
return ( this.value() && this.Filter() )
? [ this.Filter() , ... this.option_rows() ]
: this.option_rows()
}
}
}