@@ -12,7 +12,9 @@ module.exports = React.create-class do
12
12
# anchor :: Item
13
13
# class-name :: String
14
14
close-on-select : false
15
+ # values-from-paste :: String -> [Item]
15
16
default-values : []
17
+ delimiters : []
16
18
# disabled :: Boolean
17
19
# create-from-search :: [Item] -> [Item] -> String -> Item?
18
20
# filter-options :: [Item] -> [Item] -> String -> [Item]
@@ -25,6 +27,7 @@ module.exports = React.create-class do
25
27
on-blur : ((values , reason ) !-> ) # :: [Item] -> String -> Void
26
28
on-enter : ((highlighted-option ) !-> ) # :: Item -> Void
27
29
on-focus : ((values , reason ) !-> ) # :: [Item] -> String -> Void
30
+ on-paste : ((e ) !-> true ) # Event -> Boolean
28
31
# on-search-change :: String -> (a -> Void) -> Void
29
32
# on-value-change :: Item -> (a -> Void) -> Void
30
33
# options :: [Item]
@@ -40,16 +43,18 @@ module.exports = React.create-class do
40
43
# render :: a -> ReactElement
41
44
render : ->
42
45
43
- { anchor , search , values , on-anchor-change , on-search-change , on-values-change , filtered-options , options } = @ get-computed-state!
46
+ {anchor , search , values , on -anchor-change , on -search-change ,
47
+ on -values-change , filtered-options , options } = @ get-computed-state!
44
48
45
49
# props
46
- {autosize , disabled , dropdown-direction , group-id , groups , groups-as-columns , on -enter , render-group-title ,
50
+ {autosize , delimiters , disabled , dropdown-direction , group-id , groups , groups-as-columns , on -enter , render-group-title ,
47
51
transition-enter , transition-leave , transition-enter-timeout , transition-leave-timeout , uid } = @ props
48
52
49
53
ReactSelectize {
50
54
51
55
autosize
52
56
class-name : " multi-select" + if !! @ props .class-name then " #{ @ props .class-name } " else " "
57
+ delimiters
53
58
disabled
54
59
dropdown-direction
55
60
group-id
@@ -104,6 +109,18 @@ module.exports = React.create-class do
104
109
105
110
on-focus : (, reason ) !~> @ props .on-focus values , reason
106
111
112
+ # on-paste :: Event -> Boolean
113
+ on-paste :
114
+ | typeof @ props ? .values-from-paste == \undefined => @ props .on-paste
115
+ | _ => ({clipboard-data }: e ) ~>
116
+ do ~>
117
+ new-values = values ++ (@ props .values-from-paste options , values , clipboard-data .get-data \text )
118
+ <~ on -values-change new-values
119
+ on -anchor-change last new-values
120
+
121
+ e .prevent-default!
122
+ false
123
+
107
124
# STYLE
108
125
placeholder : @ props .placeholder
109
126
style : @ props .style
@@ -113,7 +130,8 @@ module.exports = React.create-class do
113
130
| typeof @ props.restore-on-backspace == \function => restore-on-backspace : @ props .restore-on-backspace
114
131
| _ => {})
115
132
<<< (switch
116
- | typeof @ props.render-no-results-found == \function => render-no-results-found : ~> @ props .render-no-results-found values , search
133
+ | typeof @ props.render-no-results-found == \function => render-no-results-found : ~>
134
+ @ props .render-no-results-found values , search
117
135
| _ => {})
118
136
119
137
@@ -147,7 +165,10 @@ module.exports = React.create-class do
147
165
148
166
# filter options and create new one from search text
149
167
filtered-options = @ props .filter-options unfiltered-options , values , search
150
- new-option = if typeof @ props.create-from-search == \function then (@ props .create-from-search filtered-options , values , search ) else null
168
+ new-option =
169
+ | typeof @ props.create-from-search == \function => @ props .create-from-search filtered-options , values , search
170
+ | _ => null
171
+
151
172
options = (if !! new-option then [{} <<< new-option <<< new-option : true ] else []) ++ filtered-options
152
173
153
174
{anchor , search , values , on -anchor-change , on -search-change , on -values-change , filtered-options , options }
0 commit comments