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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323 | 1
1
1
1
1
1
1
1
234
234
1779
233
233
233
233
1032
1032
1032
1032
49
45
43
2
94
57
30
19
19
2
2
17
17
13
1
3
17
17
17
16
1
17
17
17
18
18
3
15
14
14
14
18
18
18
3
15
18
2
233
13
220
220
5
2
215
234
234
234
234
234
468
10
15
4
10
2
2
2
433
43
43
234
234
234
8
24
24
24
226
234
234
234
234
234
41
58
58
8
58
8
5
41
4
4
2
2
2
2
2
2
1
1
1
45
45
1
44
6
1
5
1
1
1
234
234
234
1
1
471
471
471
| (function(){
var ref$, all, any, drop, camelize, difference, filter, find, findIndex, last, map, reject, isEqualToObject, React, createFactory, div, img, span, ReactSelectize;
ref$ = require('prelude-ls'), all = ref$.all, any = ref$.any, drop = ref$.drop, camelize = ref$.camelize, difference = ref$.difference, filter = ref$.filter, find = ref$.find, findIndex = ref$.findIndex, last = ref$.last, map = ref$.map, reject = ref$.reject;
isEqualToObject = require('prelude-extension').isEqualToObject;
React = require('react'), createFactory = React.createFactory, ref$ = React.DOM, div = ref$.div, img = ref$.img, span = ref$.span;
ReactSelectize = createFactory(require('./ReactSelectize'));
module.exports = React.createClass({
displayName: 'SimpleSelect',
getDefaultProps: function(){
return {
filterOptions: curry$(function(options, search){
var this$ = this;
return filter(function(it){
return it.label.toLowerCase().trim().indexOf(search.toLowerCase().trim()) > -1;
})(
options != null
? options
: []);
}),
onBlur: function(value, reason){},
onFocus: function(value, reason){},
placeholder: "",
style: {}
};
},
render: function(){
var ref$, search, value, values, onSearchChange, onValueChange, filteredOptions, options, autosize, disabled, dropdownDirection, groupId, groups, groupsAsColumns, renderGroupTitle, uid, this$ = this;
ref$ = this.getComputedState(), search = ref$.search, value = ref$.value, values = ref$.values, onSearchChange = ref$.onSearchChange, onValueChange = ref$.onValueChange, filteredOptions = ref$.filteredOptions, options = ref$.options;
ref$ = this.props, autosize = ref$.autosize, disabled = ref$.disabled, dropdownDirection = ref$.dropdownDirection, groupId = ref$.groupId, groups = ref$.groups, groupsAsColumns = ref$.groupsAsColumns, renderGroupTitle = ref$.renderGroupTitle, uid = ref$.uid;
return ReactSelectize(import$({
autosize: autosize,
className: "simple-select " + ((ref$ = this.props.className) != null ? ref$ : ''),
disabled: disabled,
dropdownDirection: dropdownDirection,
groupId: groupId,
groups: groups,
groupsAsColumns: groupsAsColumns,
renderGroupTitle: renderGroupTitle,
uid: function(it){
var uid, ref$;
uid = ((ref$ = this$.props.uid) != null
? ref$
: function(it){
return it.value;
})(it);
return (search.length === 0) + "" + uid;
},
ref: 'select',
anchor: last(values),
onAnchorChange: function(arg$, callback){
return callback();
},
open: this.state.open,
onOpenChange: function(open, callback){
if (!!open) {
return this$.showOptions(callback);
} else {
return this$.setState({
open: open
}, callback);
}
},
highlightedUid: this.state.highlightedUid,
onHighlightedUidChange: function(highlightedUid, callback){
return this$.setState({
highlightedUid: highlightedUid
}, callback);
},
firstOptionIndexToHighlight: function(){
return this$.firstOptionIndexToHighlight(options, value);
},
options: options,
renderOption: this.props.renderOption,
renderNoResultsFound: this.props.renderNoResultsFound,
search: search,
onSearchChange: function(search, callback){
return onSearchChange(search, callback);
},
values: values,
onValuesChange: function(newValues, callback){
var value;
if (newValues.length === 0) {
return onValueChange(undefined, function(){
return this$.focus(callback);
});
} else {
value = (function(){
switch (false) {
case newValues.length !== 1:
return newValues[0];
case !isEqualToObject(newValues[0], newValues[1]):
return undefined;
default:
return newValues[1];
}
}());
return function(){
return function(callback){
if (!!value) {
return onValueChange(value, callback);
} else {
return callback();
}
};
}()(function(){
return this$.setState({
open: false
}, function(){
this$.refs.select.blur();
return callback();
});
});
}
},
renderValue: function(item){
var ref$;
if (search.length > 0) {
return null;
} else {
return ((ref$ = this$.props.renderValue) != null
? ref$
: function(arg$){
var label;
label = arg$.label;
return div({
className: 'simple-value'
}, span(null, label));
})(item);
}
},
onBlur: function(arg$, reason){
(function(){
return function(callback){
if (search.length > 0) {
return onSearchChange("", callback);
} else {
return callback();
}
};
})()(function(){
return this$.props.onBlur(value, reason);
});
},
onFocus: function(arg$, reason){
this$.props.onFocus(value, reason);
},
placeholder: this.props.placeholder,
style: this.props.style
}, (function(){
switch (false) {
case typeof this.props.restoreOnBackspace !== 'function':
return {
restoreOnBackspace: this.props.restoreOnBackspace
};
default:
return import$({}, (function(){
switch (false) {
case typeof this.props.renderNoResultsFound !== 'function':
return {
renderNoResultsFound: function(){
return this$.props.renderNoResultsFound(value, search);
}
};
default:
return {};
}
}.call(this)));
}
}.call(this))));
},
getComputedState: function(){
var search, value, values, ref$, onSearchChange, onValueChange, optionsFromChildren, unfilteredOptions, filteredOptions, newOption, options, this$ = this;
search = this.props.hasOwnProperty('search')
? this.props.search
: this.state.search;
value = this.props.hasOwnProperty('value')
? this.props.value
: this.state.value;
values = !!value
? [value]
: [];
ref$ = map(function(p){
switch (false) {
case !(this$.props.hasOwnProperty(p) && this$.props.hasOwnProperty(camelize("on-" + p + "-change"))):
return this$.props[camelize("on-" + p + "-change")];
case !(this$.props.hasOwnProperty(p) && !this$.props.hasOwnProperty(camelize("on-" + p + "-change"))):
return function(arg$, callback){
return callback();
};
case !(!this$.props.hasOwnProperty(p) && this$.props.hasOwnProperty(camelize("on-" + p + "-change"))):
return function(o, callback){
var ref$;
return this$.setState((ref$ = {}, ref$[p + ""] = o, ref$), function(){
return this$.props[camelize("on-" + p + "-change")](o, callback);
});
};
case !(!this$.props.hasOwnProperty(p) && !this$.props.hasOwnProperty(camelize("on-" + p + "-change"))):
return function(o, callback){
var ref$;
return this$.setState((ref$ = {}, ref$[p + ""] = o, ref$), callback);
};
}
})(
['search', 'value']), onSearchChange = ref$[0], onValueChange = ref$[1];
optionsFromChildren = (function(){
var ref$;
switch (false) {
case !((ref$ = this.props) != null && ref$.children):
return map(function(arg$){
var ref$, value, children;
ref$ = arg$.props, value = ref$.value, children = ref$.children;
return {
label: children,
value: value
};
})(
this.props.children);
default:
return [];
}
}.call(this));
unfilteredOptions = this.props.hasOwnProperty('options') ? (ref$ = this.props.options) != null
? ref$
: [] : optionsFromChildren;
filteredOptions = this.props.filterOptions(unfilteredOptions, search);
newOption = typeof this.props.createFromSearch === 'function' ? this.props.createFromSearch(filteredOptions, search) : null;
options = (!!newOption
? [(ref$ = import$({}, newOption), ref$.newOption = true, ref$)]
: []).concat(filteredOptions);
return {
search: search,
value: value,
values: values,
onSearchChange: onSearchChange,
onValueChange: onValueChange,
filteredOptions: filteredOptions,
options: options
};
},
getInitialState: function(){
return {
highlightedUid: undefined,
open: false,
search: "",
value: undefined
};
},
firstOptionIndexToHighlight: function(options, value){
var index, ref$, this$ = this;
index = !!value ? findIndex(function(it){
return isEqualToObject(it, value);
}, options) : undefined;
switch (false) {
case typeof index === 'undefined':
return index;
case options.length !== 1:
return 0;
case typeof (options != null ? (ref$ = options[0]) != null ? ref$.newOption : void 8 : void 8) !== 'undefined':
return 0;
default:
if (all(function(it){
return typeof it.selectable === 'boolean' && !it.selectable;
})(
drop(1)(
options))) {
return 0;
} else {
return 1;
}
}
},
focus: function(callback){
this.refs.select.focus();
return this.showOptions(callback);
},
highlightFirstSelectableOption: function(){
var ref$, options, value;
if (!this.state.open) {
return;
}
ref$ = this.getComputedState(), options = ref$.options, value = ref$.value;
this.refs.select.highlightAndScrollToSelectableOption(this.firstOptionIndexToHighlight(options, value), 1);
},
showOptions: function(callback){
this.setState({
open: (function(){
switch (false) {
case !this.props.disabled:
return false;
default:
return true;
}
}.call(this))
}, callback);
},
value: function(){
if (this.props.hasOwnProperty('value')) {
return this.props.value;
} else {
return this.state.value;
}
}
});
function curry$(f, bound){
var context,
_curry = function(args) {
return f.length > 1 ? function(){
var params = args ? args.concat() : [];
context = bound ? context || this : this;
return params.push.apply(params, arguments) <
f.length && arguments.length ?
_curry.call(context, params) : f.apply(context, params);
} : f;
};
return _curry();
}
function import$(obj, src){
var own = {}.hasOwnProperty;
for (var key in src) Eif (own.call(src, key)) obj[key] = src[key];
return obj;
}
}).call(this);
|