@types/selectize 0.12.31 → 0.12.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
selectize/index.d.ts CHANGED
@@ -1,637 +1,673 @@
1
- // Type definitions for Selectize 0.12.14
2
- // Project: https://github.com/brianreavis/selectize.js
3
- // Definitions by: Adi Dahiya <https://github.com/adidahiya>, Natalie Bausch <https://github.com/naBausch>
4
- // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
-
6
- declare namespace Selectize {
7
- // see https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md
8
- // option identifiers are parameterized by T; data is parameterized by U
9
- interface IOptions<T, U> {
10
-
11
- // General
12
- // ------------------------------------------------------------------------------------------------------------
13
-
14
- /**
15
- * The string to separate items by. This option is only used when Selectize is instantiated from a
16
- * <input type="text"> element.
17
- *
18
- * Default: ','
19
- */
20
- delimiter?: string;
21
-
22
- /**
23
- * Enable or disable international character support.
24
- *
25
- * Default: true
26
- */
27
- diacritics?: boolean;
28
-
29
- /**
30
- * Allows the user to create a new items that aren't in the list of options.
31
- * This option can be any of the following: "true", "false" (disabled), or a function that accepts two
32
- * arguments: "input" and "callback". The callback should be invoked with the final data for the option.
33
- *
34
- * Default: false
35
- */
36
- create?: any;
37
-
38
- /**
39
- * If true, when user exits the field (clicks outside of input or presses ESC) new option is created and
40
- * selected (if `create`-option is enabled).
41
- *
42
- * Default: false
43
- */
44
- createOnBlur?: boolean;
45
-
46
- /**
47
- * Specifies a RegExp or String containing a regular expression that the current search filter must match to
48
- * be allowed to be created. May also be a predicate function that takes the filter text and returns whether
49
- * it is allowed.
50
- *
51
- * Default: null
52
- */
53
- createFilter?: any;
54
-
55
- /**
56
- * Toggles match highlighting within the dropdown menu.
57
- *
58
- * Default: true
59
- */
60
- highlight?: boolean;
61
-
62
- /**
63
- * If false, items created by the user will not show up as available options once they are unselected.
64
- *
65
- * Default: true
66
- */
67
- persist?: boolean;
68
-
69
- /**
70
- * Show the dropdown immediately when the control receives focus.
71
- *
72
- * Default: true
73
- */
74
- openOnFocus?: boolean;
75
-
76
- /**
77
- * The max number of items to render at once in the dropdown list of options.
78
- *
79
- * Default: 1000
80
- */
81
- maxOptions?: number;
82
-
83
- /**
84
- * The max number of items the user can select.
85
- *
86
- * Default: Infinity
87
- */
88
- maxItems?: number;
89
-
90
- /**
91
- * If true, the items that are currently selected will not be shown in the dropdown list of available options.
92
- *
93
- * Default: false
94
- */
95
- hideSelected?: boolean;
96
-
97
- /**
98
- * If true, Selectize will treat any options with a "" value like normal. This defaults to false to
99
- * accomodate the common <select> practice of having the first empty option act as a placeholder.
100
- *
101
- * Default: false
102
- */
103
- allowEmptyOption?: boolean;
104
-
105
- /**
106
- * The animation duration (in milliseconds) of the scroll animation triggered when going [up] and [down] in
107
- * the options dropdown.
108
- *
109
- * Default: 60
110
- */
111
- scrollDuration?: number;
112
-
113
- /**
114
- * The number of milliseconds to wait before requesting options from the server or null.
115
- * If null, throttling is disabled.
116
- *
117
- * Default: 300
118
- */
119
- loadThrottle?: number;
120
-
121
- /**
122
- * If true, the "load" function will be called upon control initialization (with an empty search).
123
- * Alternatively it can be set to "focus" to call the "load" function when control receives focus.
124
- *
125
- * Default: false
126
- */
127
- preload?: any;
128
-
129
- /**
130
- * The element the dropdown menu is appended to. This should be "body" or null.
131
- * If null, the dropdown will be appended as a child of the selectize control.
132
- *
133
- * Default: null
134
- */
135
- dropdownParent?: string;
136
-
137
- /**
138
- * Sets if the "Add..." option should be the default selection in the dropdown.
139
- *
140
- * Default: false
141
- */
142
- addPrecedence?: boolean;
143
-
144
- /**
145
- * If true, the tab key will choose the currently selected item.
146
- *
147
- * Default: false
148
- */
149
- selectOnTab?: boolean;
150
-
151
- /**
152
- * Plugins to use
153
- *
154
- * Default: null
155
- */
156
- plugins?: string[] | IPluginOption[] | { [name: string]: any };
157
-
158
- // Data / Searching
159
- // ------------------------------------------------------------------------------------------------------------
160
-
161
- /**
162
- * Options available to select; array of objects. If your element is <select> with <option>s specified this
163
- * property gets populated accordingly. Setting this property is convenient if you have your data as an
164
- * array and want to automatically generate the <option>s.
165
- *
166
- * Default: []
167
- */
168
- options?: U[];
169
-
170
- /**
171
- * The <option> attribute from which to read JSON data about the option.
172
- *
173
- * Default: "data-data"
174
- */
175
- dataAttr?: string;
176
-
177
- /**
178
- * The name of the property to use as the "value" when an item is selected.
179
- *
180
- * Default: "value"
181
- */
182
- valueField?: string;
183
-
184
- /**
185
- * Option groups that options will be bucketed into.
186
- * If your element is a <select> with <optgroup>s this property gets populated automatically.
187
- * Make sure each object in the array has a property named whatever "optgroupValueField" is set to.
188
- */
189
- optgroups?: U[];
190
-
191
- /**
192
- * The name of the option group property that serves as its unique identifier.
193
- *
194
- * Default: "value"
195
- */
196
- optgroupValueField?: string;
197
-
198
- /**
199
- * The name of the property to render as an option / item label (not needed when custom rendering
200
- * functions are defined).
201
- *
202
- * Default: "text"
203
- */
204
- labelField?: string;
205
-
206
- /**
207
- * The name of the property to render as an option group label (not needed when custom rendering
208
- * functions are defined).
209
- *
210
- * Default: "label"
211
- */
212
- optgroupLabelField?: string;
213
-
214
- /**
215
- * The name of the property to group items by.
216
- *
217
- * Default: "optgroup"
218
- */
219
- optgroupField?: string;
220
-
221
- /**
222
- * A single field or an array of fields to sort by. Each item in the array should be an object containing at
223
- * least a "field" property. Optionally, "direction" can be set to "asc" or "desc". The order of the array
224
- * defines the sort precedence.
225
- *
226
- * Unless present, a special "$score" field will be automatically added to the beginning of the sort list.
227
- * This will make results sorted primarily by match quality (descending).
228
- *
229
- * Default: "$order"
230
- */
231
- sortField?: any;
232
-
233
- /**
234
- * An array of property names to analyze when filtering options.
235
- *
236
- * Default: ["text"]
237
- */
238
- searchField?: any;
239
-
240
- /**
241
- * When searching for multiple terms (separated by a space), this is the operator used. Can be "and" or "or".
242
- *
243
- * Default: "and"
244
- */
245
- searchConjunction?: string;
246
-
247
- /**
248
- * If truthy, Selectize will make all optgroups be in the same order as they were added (by the `$order`
249
- * property). Otherwise, it will order based on the score of the results in each.
250
- *
251
- * Default: false
252
- */
253
- lockOptgroupOrder?: boolean;
254
-
255
- /**
256
- * An array of optgroup values that indicates the order they should be listed in in the dropdown.
257
- * If not provided, groups will be ordered by the ranking of the options within them.
258
- *
259
- * Default: null
260
- */
261
- optgroupOrder?: string[];
262
-
263
- /**
264
- * Copy the original input classes to the Dropdown element.
265
- *
266
- * Default: true
267
- */
268
- copyClassesToDropdown?: boolean;
269
-
270
- // Callbacks
271
- // ------------------------------------------------------------------------------------------------------------
272
-
273
- /**
274
- * Invoked when new options should be loaded from the server.
275
- */
276
- load?(query: string, callback: Function): any;
277
-
278
- /**
279
- * Overrides the scoring function used to sort available options. The provided function should return a
280
- * function that returns a number greater than or equal to zero to represent the "score" of an item
281
- * (the function's first argument). If 0, the option is declared not a match.
282
- */
283
- score?(search: ISearch): (item: any) => number;
284
-
285
- /**
286
- * Invoked once the control is completely initialized.
287
- */
288
- onInitialize?(): any;
289
-
290
- /**
291
- * Invoked when the value of the control changes.
292
- *
293
- * If single select, value is of type T.
294
- * If multi select, value is of type T[].
295
- */
296
- onChange?(value: any): any;
297
-
298
- /**
299
- * Invoked when an item is selected.
300
- */
301
- onItemAdd?(value: T, item: JQuery): any;
302
-
303
- /**
304
- * Invoked when an item is deselected.
305
- */
306
- onItemRemove?(value: T): any;
307
-
308
- /**
309
- * Invoked when the control is manually cleared via the clear() method.
310
- */
311
- onClear?(): any;
312
-
313
- /**
314
- * Invoked when the user attempts to delete the current selection.
315
- */
316
- onDelete?(values: T[]): any;
317
-
318
- /**
319
- * Invoked when a new option is added to the available options list.
320
- */
321
- onOptionAdd?(value: T, data: U): any;
322
-
323
- /**
324
- * Invoked when an option is removed from the available options.
325
- */
326
- onOptionRemove?(value: T): any;
327
-
328
- /**
329
- * Invoked when the dropdown opens.
330
- */
331
- onDropdownOpen?(dropdown: JQuery): any;
332
-
333
- /**
334
- * Invoked when the dropdown closes.
335
- */
336
- onDropdownClose?(dropdown: JQuery): any;
337
-
338
- /**
339
- * Invoked when the user types while filtering options.
340
- */
341
- onType?(srt: string): any;
342
-
343
- /**
344
- * Invoked when new options have been loaded and added to the control (via the "load" option or "load" API method).
345
- */
346
- onLoad?(data: U[]): any;
347
-
348
- // Rendering
349
- // ------------------------------------------------------------------------------------------------------------
350
-
351
- render?: ICustomRenderers<U>;
352
- }
353
-
354
- /**
355
- * Custom rendering functions. Each function should accept two arguments: "data" and "escape" and return
356
- * HTML (string) with a single root element. The "escape" argument is a function that takes a string and
357
- * escapes all special HTML characters. This is very important to use to prevent XSS vulnerabilities.
358
- */
359
- interface ICustomRenderers<U> {
360
- // An option in the dropdown list of available options.
361
- option?(data: U, escape: (input: string) => string): string;
362
-
363
- // An item the user has selected.
364
- item?(data: U, escape: (input: string) => string): string;
365
-
366
- // The "create new" option at the bottom of the dropdown. The data contains one property: "input"
367
- // (which is what the user has typed).
368
- option_create?(data: U, escape: (input: string) => string): string;
369
-
370
- // The header of an option group.
371
- optgroup_header?(data: U, escape: (input: string) => string): string;
372
-
373
- // The wrapper for an optgroup. The "html" property in the data will be the raw html of the optgroup's header
374
- // and options.
375
- optgroup?(data: U, escape: (input: string) => string): string;
376
- }
377
-
378
- // see https://github.com/brianreavis/selectize.js/blob/master/docs/api.md
379
- interface IApi<T, U> {
380
- /**
381
- * An array of selected values.
382
- */
383
- items: T[];
384
-
385
- /**
386
- * An object containing the entire pool of options. The object is keyed by each object's value.
387
- */
388
- options: { [value: string]: U };
389
-
390
- // Dropdown Options
391
- // ------------------------------------------------------------------------------------------------------------
392
-
393
- /**
394
- * Adds an available option. If it already exists, nothing will happen.
395
- * Note: this does not refresh the options list dropdown (use refreshOptions() for that).
396
- */
397
- addOption(data: U): void;
398
-
399
- /**
400
- * Updates an option available for selection. If it is visible in the selected items or options dropdown,
401
- * it will be re-rendered automatically.
402
- */
403
- updateOption(value: T, data: U): void;
404
-
405
- /**
406
- * Removes the option identified by the given value.
407
- */
408
- removeOption(value: T): void;
409
-
410
- /**
411
- * Removes all options from the control.
412
- */
413
- clearOptions(): void;
414
-
415
- /**
416
- * Retrieves the jQuery element for the option identified by the given value.
417
- */
418
- getOption(value: T): JQuery;
419
-
420
- /**
421
- * Retrieves the jQuery element for the previous or next option, relative to the currently highlighted option.
422
- * The "direction" argument should be 1 for "next" or -1 for "previous".
423
- */
424
- getAdjacentOption(value: T, direction: number): void;
425
-
426
- /**
427
- * Refreshes the list of available options shown in the autocomplete dropdown menu.
428
- */
429
- refreshOptions(triggerDropdown: boolean): void;
430
-
431
- // Selected Items
432
- // ------------------------------------------------------------------------------------------------------------
433
-
434
- /**
435
- * Resets / clears all selected items from the control.
436
- */
437
- clear(silent?: boolean): void;
438
-
439
- /**
440
- * Returns the jQuery element of the item matching the given value.
441
- */
442
- getItem(value: T): JQuery;
443
-
444
- /**
445
- * "Selects" an item. Adds it to the list at the current caret position.
446
- */
447
- addItem(value: T, silent?: boolean): void;
448
-
449
- /**
450
- * Removes the selected item matching the provided value.
451
- */
452
- removeItem(value: T, silent?: boolean): void;
453
-
454
- /**
455
- * Invokes the "create" method provided in the selectize options that should provide the data for the
456
- * new item, given the user input. Once this completes, it will be added to the item list.
457
- */
458
- createItem(value: T, triggerDropdown?: boolean, callback?: (data?: any) => void): void;
459
-
460
- /**
461
- * Re-renders the selected item lists.
462
- */
463
- refreshItems(): void;
464
-
465
- // Optgroups
466
- // ------------------------------------------------------------------------------------------------------------
467
-
468
- /**
469
- * Registers a new optgroup for options to be bucketed into.
470
- * The "id" argument refers to a value of the property in option identified by the "optgroupField" setting.
471
- */
472
- addOptionGroup(id: string, data: U): void;
473
-
474
- // Events
475
- // ------------------------------------------------------------------------------------------------------------
476
-
477
- /**
478
- * Adds an event listener.
479
- */
480
- on(eventName: string, handler: Function): void;
481
-
482
- /**
483
- * Removes an event listener. If no handler is provided, all event listeners are removed.
484
- */
485
- off(eventName: string, handler?: Function): void;
486
-
487
- /**
488
- * Triggers event listeners.
489
- */
490
- trigger(eventName: string, ...args: any[]): void;
491
-
492
- // Dropdown Actions
493
- // ------------------------------------------------------------------------------------------------------------
494
-
495
- /**
496
- * Shows the autocomplete dropdown containing the available options.
497
- */
498
- open(): void;
499
-
500
- /**
501
- * Closes the autocomplete dropdown menu.
502
- */
503
- close(): void;
504
-
505
- /**
506
- * Calculates and applies the appropriate position of the dropdown.
507
- */
508
- positionDropdown(): void;
509
-
510
- // Other
511
- // ------------------------------------------------------------------------------------------------------------
512
-
513
- /**
514
- * Destroys the control and unbinds event listeners so that it can be garbage collected.
515
- */
516
- destroy(): void;
517
-
518
- /**
519
- * Loads options by invoking the the provided function. The function should accept one argument (callback)
520
- * and invoke the callback with the results once they are available.
521
- */
522
- load(callback: (results: any) => any): void;
523
-
524
- /**
525
- * Brings the control into focus.
526
- */
527
- focus(): void;
528
-
529
- /**
530
- * Forces the control out of focus.
531
- */
532
- blur(): void;
533
-
534
- /**
535
- * Disables user input on the control (note: the control can still receive focus).
536
- */
537
- lock(): void;
538
-
539
- /**
540
- * Re-enables user input on the control.
541
- */
542
- unlock(): void;
543
-
544
- /**
545
- * Disables user input on the control completely. While disabled, it cannot receive focus.
546
- */
547
- disable(): void;
548
-
549
- /**
550
- * Enables the control so that it can respond to focus and user input.
551
- */
552
- enable(): void;
553
-
554
- /**
555
- * Returns the value of the control. If multiple items can be selected (e.g. <select multiple>), this
556
- * returns an array. If only one item can be selected, this returns a string.
557
- */
558
- getValue(): any;
559
-
560
- /**
561
- * Resets the selected items to the given value(s).
562
- */
563
- setValue(value: T, silent?: boolean): void;
564
- setValue(value: T[], silent?: boolean): void;
565
-
566
- /**
567
- * Moves the caret to the specified position ("index" being the index in the list of selected items).
568
- */
569
- setCaret(index: number): void;
570
-
571
- /**
572
- * Returns whether or not the user can select more items.
573
- */
574
- isFull(): boolean;
575
-
576
- /**
577
- * Clears the render cache. Takes an optional template argument (e.g. "option", "item") to clear only that cache.
578
- */
579
- clearCache(template?: string): void;
580
-
581
- /**
582
- * When the `settings.placeholder` value is changed, the new placeholder will be displayed.
583
- */
584
- updatePlaceholder(): void;
585
- }
586
-
587
- interface ISearchToken {
588
- regex: RegExp;
589
- string: string;
590
- }
591
-
592
- interface ISearchResult {
593
- id: string;
594
- score: number;
595
- }
596
-
597
- interface ISearch {
598
- /**
599
- * Original search options.
600
- */
601
- options: any;
602
-
603
- /**
604
- * The raw user input
605
- */
606
- query: string;
607
-
608
- /**
609
- * An array containing parsed search tokens. A token is an object containing two properties: "string" and "regex".
610
- */
611
- tokens: ISearchToken[];
612
-
613
- /**
614
- * The total number of results.
615
- */
616
- total: number;
617
-
618
- /**
619
- * A list of matched results. Each result is an object containing two properties: "score" and "id".
620
- */
621
- items: ISearchResult[];
622
- }
623
-
624
- // see https://github.com/selectize/selectize.js/blob/master/docs/plugins.md
625
- interface IPluginOption {
626
- name: string;
627
- options: any;
628
- }
629
- }
630
-
631
- interface JQuery {
632
- selectize(options?: Selectize.IOptions<any, any>): JQuery;
633
- }
634
-
635
- interface HTMLElement {
636
- selectize: Selectize.IApi<any, any>;
637
- }
1
+ // Type definitions for Selectize 0.12.14
2
+ // Project: https://github.com/brianreavis/selectize.js
3
+ // Definitions by: Adi Dahiya <https://github.com/adidahiya>, Natalie Bausch <https://github.com/naBausch>
4
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
+ // TypeScript Version: 2.3
6
+
7
+ declare namespace Selectize {
8
+ // see https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md
9
+ // option identifiers are parameterized by T; data is parameterized by U
10
+ interface IOptions<T, U> {
11
+
12
+ // General
13
+ // ------------------------------------------------------------------------------------------------------------
14
+
15
+ /**
16
+ * An array of the initial selected values. By default this is populated from the original input element.
17
+ */
18
+ items?: T[] | undefined;
19
+
20
+ /**
21
+ * The placeholder of the control (displayed when nothing is selected / typed).
22
+ * Defaults to input element's placeholder, unless this one is specified.
23
+ */
24
+ placeholder?: string | undefined;
25
+
26
+ /**
27
+ * The string to separate items by. This option is only used when Selectize is instantiated from a
28
+ * <input type="text"> element.
29
+ *
30
+ * Default: ','
31
+ */
32
+ delimiter?: string | undefined;
33
+
34
+ /**
35
+ * Enable or disable international character support.
36
+ *
37
+ * Default: true
38
+ */
39
+ diacritics?: boolean | undefined;
40
+
41
+ /**
42
+ * Allows the user to create a new items that aren't in the list of options.
43
+ * This option can be any of the following: "true", "false" (disabled), or a function that accepts two
44
+ * arguments: "input" and "callback". The callback should be invoked with the final data for the option.
45
+ *
46
+ * Default: false
47
+ */
48
+ create?: any;
49
+
50
+ /**
51
+ * If true, when user exits the field (clicks outside of input or presses ESC) new option is created and
52
+ * selected (if `create`-option is enabled).
53
+ *
54
+ * Default: false
55
+ */
56
+ createOnBlur?: boolean | undefined;
57
+
58
+ /**
59
+ * Specifies a RegExp or String containing a regular expression that the current search filter must match to
60
+ * be allowed to be created. May also be a predicate function that takes the filter text and returns whether
61
+ * it is allowed.
62
+ *
63
+ * Default: null
64
+ */
65
+ createFilter?: any;
66
+
67
+ /**
68
+ * Toggles match highlighting within the dropdown menu.
69
+ *
70
+ * Default: true
71
+ */
72
+ highlight?: boolean | undefined;
73
+
74
+ /**
75
+ * If false, items created by the user will not show up as available options once they are unselected.
76
+ *
77
+ * Default: true
78
+ */
79
+ persist?: boolean | undefined;
80
+
81
+ /**
82
+ * Show the dropdown immediately when the control receives focus.
83
+ *
84
+ * Default: true
85
+ */
86
+ openOnFocus?: boolean | undefined;
87
+
88
+ /**
89
+ * The max number of items to render at once in the dropdown list of options.
90
+ *
91
+ * Default: 1000
92
+ */
93
+ maxOptions?: number | undefined;
94
+
95
+ /**
96
+ * The max number of items the user can select.
97
+ *
98
+ * Default: Infinity
99
+ */
100
+ maxItems?: number | undefined;
101
+
102
+ /**
103
+ * If true, the items that are currently selected will not be shown in the dropdown list of available options.
104
+ *
105
+ * Default: false
106
+ */
107
+ hideSelected?: boolean | undefined;
108
+
109
+ /**
110
+ * If true, the dropdown will be closed after a selection is made.
111
+ *
112
+ * Default: false
113
+ */
114
+ closeAfterSelect?: boolean | undefined;
115
+
116
+ /**
117
+ * If true, Selectize will treat any options with a "" value like normal. This defaults to false to
118
+ * accomodate the common <select> practice of having the first empty option act as a placeholder.
119
+ *
120
+ * Default: false
121
+ */
122
+ allowEmptyOption?: boolean | undefined;
123
+
124
+ /**
125
+ * The animation duration (in milliseconds) of the scroll animation triggered when going [up] and [down] in
126
+ * the options dropdown.
127
+ *
128
+ * Default: 60
129
+ */
130
+ scrollDuration?: number | undefined;
131
+
132
+ /**
133
+ * The number of milliseconds to wait before requesting options from the server or null.
134
+ * If null, throttling is disabled.
135
+ *
136
+ * Default: 300
137
+ */
138
+ loadThrottle?: number | undefined;
139
+
140
+ /**
141
+ * If true, the "load" function will be called upon control initialization (with an empty search).
142
+ * Alternatively it can be set to "focus" to call the "load" function when control receives focus.
143
+ *
144
+ * Default: false
145
+ */
146
+ preload?: boolean | 'focus' | undefined;
147
+
148
+ /**
149
+ * The element the dropdown menu is appended to. This should be "body" or null.
150
+ * If null, the dropdown will be appended as a child of the selectize control.
151
+ *
152
+ * Default: null
153
+ */
154
+ dropdownParent?: string | undefined;
155
+
156
+ /**
157
+ * Sets if the "Add..." option should be the default selection in the dropdown.
158
+ *
159
+ * Default: false
160
+ */
161
+ addPrecedence?: boolean | undefined;
162
+
163
+ /**
164
+ * If true, the tab key will choose the currently selected item.
165
+ *
166
+ * Default: false
167
+ */
168
+ selectOnTab?: boolean | undefined;
169
+
170
+ /**
171
+ * Plugins to use
172
+ *
173
+ * Default: null
174
+ */
175
+ plugins?: string[] | IPluginOption[] | { [name: string]: any } | undefined;
176
+
177
+ // Data / Searching
178
+ // ------------------------------------------------------------------------------------------------------------
179
+
180
+ /**
181
+ * Options available to select; array of objects. If your element is <select> with <option>s specified this
182
+ * property gets populated accordingly. Setting this property is convenient if you have your data as an
183
+ * array and want to automatically generate the <option>s.
184
+ *
185
+ * Default: []
186
+ */
187
+ options?: U[] | undefined;
188
+
189
+ /**
190
+ * The <option> attribute from which to read JSON data about the option.
191
+ *
192
+ * Default: "data-data"
193
+ */
194
+ dataAttr?: string | undefined;
195
+
196
+ /**
197
+ * The name of the property to use as the "value" when an item is selected.
198
+ *
199
+ * Default: "value"
200
+ */
201
+ valueField?: string | undefined;
202
+
203
+ /**
204
+ * Option groups that options will be bucketed into.
205
+ * If your element is a <select> with <optgroup>s this property gets populated automatically.
206
+ * Make sure each object in the array has a property named whatever "optgroupValueField" is set to.
207
+ */
208
+ optgroups?: U[] | undefined;
209
+
210
+ /**
211
+ * The name of the option group property that serves as its unique identifier.
212
+ *
213
+ * Default: "value"
214
+ */
215
+ optgroupValueField?: string | undefined;
216
+
217
+ /**
218
+ * The name of the property to render as an option / item label (not needed when custom rendering
219
+ * functions are defined).
220
+ *
221
+ * Default: "text"
222
+ */
223
+ labelField?: string | undefined;
224
+
225
+ /**
226
+ * The name of the property to render as an option group label (not needed when custom rendering
227
+ * functions are defined).
228
+ *
229
+ * Default: "label"
230
+ */
231
+ optgroupLabelField?: string | undefined;
232
+
233
+ /**
234
+ * The name of the property to group items by.
235
+ *
236
+ * Default: "optgroup"
237
+ */
238
+ optgroupField?: string | undefined;
239
+
240
+ /**
241
+ * The name of the property to disabled option and optgroup.
242
+ *
243
+ * Default: 'disabled'
244
+ */
245
+ disabledField?: string | undefined;
246
+
247
+ /**
248
+ * A single field or an array of fields to sort by. Each item in the array should be an object containing at
249
+ * least a "field" property. Optionally, "direction" can be set to "asc" or "desc". The order of the array
250
+ * defines the sort precedence.
251
+ *
252
+ * Unless present, a special "$score" field will be automatically added to the beginning of the sort list.
253
+ * This will make results sorted primarily by match quality (descending).
254
+ *
255
+ * Default: "$order"
256
+ */
257
+ sortField?: string | { field: string, direction?: 'asc' | 'desc' | undefined }[] | undefined;
258
+
259
+ /**
260
+ * An array of property names to analyze when filtering options.
261
+ *
262
+ * Default: ["text"]
263
+ */
264
+ searchField?: string | string[] | undefined;
265
+
266
+ /**
267
+ * When searching for multiple terms (separated by a space), this is the operator used. Can be "and" or "or".
268
+ *
269
+ * Default: "and"
270
+ */
271
+ searchConjunction?: string | undefined;
272
+
273
+ /**
274
+ * If truthy, Selectize will make all optgroups be in the same order as they were added (by the `$order`
275
+ * property). Otherwise, it will order based on the score of the results in each.
276
+ *
277
+ * Default: false
278
+ */
279
+ lockOptgroupOrder?: boolean | undefined;
280
+
281
+ /**
282
+ * An array of optgroup values that indicates the order they should be listed in in the dropdown.
283
+ * If not provided, groups will be ordered by the ranking of the options within them.
284
+ *
285
+ * Default: null
286
+ */
287
+ optgroupOrder?: string[] | undefined;
288
+
289
+ /**
290
+ * Copy the original input classes to the Dropdown element.
291
+ *
292
+ * Default: true
293
+ */
294
+ copyClassesToDropdown?: boolean | undefined;
295
+
296
+ // Callbacks
297
+ // ------------------------------------------------------------------------------------------------------------
298
+
299
+ /**
300
+ * Invoked when new options should be loaded from the server.
301
+ */
302
+ load?(query: string, callback: Function): any;
303
+
304
+ /**
305
+ * Overrides the scoring function used to sort available options. The provided function should return a
306
+ * function that returns a number greater than or equal to zero to represent the "score" of an item
307
+ * (the function's first argument). If 0, the option is declared not a match.
308
+ */
309
+ score?(search: ISearch): (item: any) => number;
310
+
311
+ /**
312
+ * Invoked once the control is completely initialized.
313
+ */
314
+ onInitialize?(): any;
315
+
316
+ /**
317
+ * Invoked when the control gains focus.
318
+ */
319
+ onFocus?(): any;
320
+
321
+ /**
322
+ * Invoked when the control loses focus.
323
+ */
324
+ onBlur?(): any;
325
+
326
+ /**
327
+ * Invoked when the value of the control changes.
328
+ *
329
+ * If single select, value is of type T.
330
+ * If multi select, value is of type T[].
331
+ */
332
+ onChange?(value: any): any;
333
+
334
+ /**
335
+ * Invoked when an item is selected.
336
+ */
337
+ onItemAdd?(value: T, item: JQuery): any;
338
+
339
+ /**
340
+ * Invoked when an item is deselected.
341
+ */
342
+ onItemRemove?(value: T): any;
343
+
344
+ /**
345
+ * Invoked when the control is manually cleared via the clear() method.
346
+ */
347
+ onClear?(): any;
348
+
349
+ /**
350
+ * Invoked when the user attempts to delete the current selection.
351
+ */
352
+ onDelete?(values: T[]): any;
353
+
354
+ /**
355
+ * Invoked when a new option is added to the available options list.
356
+ */
357
+ onOptionAdd?(value: T, data: U): any;
358
+
359
+ /**
360
+ * Invoked when an option is removed from the available options.
361
+ */
362
+ onOptionRemove?(value: T): any;
363
+
364
+ /**
365
+ * Invoked when the dropdown opens.
366
+ */
367
+ onDropdownOpen?(dropdown: JQuery): any;
368
+
369
+ /**
370
+ * Invoked when the dropdown closes.
371
+ */
372
+ onDropdownClose?(dropdown: JQuery): any;
373
+
374
+ /**
375
+ * Invoked when the user types while filtering options.
376
+ */
377
+ onType?(srt: string): any;
378
+
379
+ /**
380
+ * Invoked when new options have been loaded and added to the control (via the "load" option or "load" API method).
381
+ */
382
+ onLoad?(data: U[]): any;
383
+
384
+ // Rendering
385
+ // ------------------------------------------------------------------------------------------------------------
386
+
387
+ render?: ICustomRenderers<U> | undefined;
388
+ }
389
+
390
+ /**
391
+ * Custom rendering functions. Each function should accept two arguments: "data" and "escape" and return
392
+ * HTML (string) with a single root element. The "escape" argument is a function that takes a string and
393
+ * escapes all special HTML characters. This is very important to use to prevent XSS vulnerabilities.
394
+ */
395
+ interface ICustomRenderers<U> {
396
+ // An option in the dropdown list of available options.
397
+ option?(data: U, escape: (input: string) => string): string;
398
+
399
+ // An item the user has selected.
400
+ item?(data: U, escape: (input: string) => string): string;
401
+
402
+ // The "create new" option at the bottom of the dropdown. The data contains one property: "input"
403
+ // (which is what the user has typed).
404
+ option_create?(data: U, escape: (input: string) => string): string;
405
+
406
+ // The header of an option group.
407
+ optgroup_header?(data: U, escape: (input: string) => string): string;
408
+
409
+ // The wrapper for an optgroup. The "html" property in the data will be the raw html of the optgroup's header
410
+ // and options.
411
+ optgroup?(data: U, escape: (input: string) => string): string;
412
+ }
413
+
414
+ // see https://github.com/brianreavis/selectize.js/blob/master/docs/api.md
415
+ interface IApi<T, U> {
416
+ /**
417
+ * An array of selected values.
418
+ */
419
+ items: T[];
420
+
421
+ /**
422
+ * An object containing the entire pool of options. The object is keyed by each object's value.
423
+ */
424
+ options: { [value: string]: U };
425
+
426
+ // Dropdown Options
427
+ // ------------------------------------------------------------------------------------------------------------
428
+
429
+ /**
430
+ * Adds an available option. If it already exists, nothing will happen.
431
+ * Note: this does not refresh the options list dropdown (use refreshOptions() for that).
432
+ */
433
+ addOption(data: U): void;
434
+
435
+ /**
436
+ * Updates an option available for selection. If it is visible in the selected items or options dropdown,
437
+ * it will be re-rendered automatically.
438
+ */
439
+ updateOption(value: T, data: U): void;
440
+
441
+ /**
442
+ * Removes the option identified by the given value.
443
+ */
444
+ removeOption(value: T): void;
445
+
446
+ /**
447
+ * Removes all options from the control.
448
+ */
449
+ clearOptions(): void;
450
+
451
+ /**
452
+ * Retrieves the jQuery element for the option identified by the given value.
453
+ */
454
+ getOption(value: T): JQuery;
455
+
456
+ /**
457
+ * Retrieves the jQuery element for the previous or next option, relative to the currently highlighted option.
458
+ * The "direction" argument should be 1 for "next" or -1 for "previous".
459
+ */
460
+ getAdjacentOption(value: T, direction: number): void;
461
+
462
+ /**
463
+ * Refreshes the list of available options shown in the autocomplete dropdown menu.
464
+ */
465
+ refreshOptions(triggerDropdown: boolean): void;
466
+
467
+ // Selected Items
468
+ // ------------------------------------------------------------------------------------------------------------
469
+
470
+ /**
471
+ * Resets / clears all selected items from the control.
472
+ */
473
+ clear(silent?: boolean): void;
474
+
475
+ /**
476
+ * Returns the jQuery element of the item matching the given value.
477
+ */
478
+ getItem(value: T): JQuery;
479
+
480
+ /**
481
+ * "Selects" an item. Adds it to the list at the current caret position.
482
+ */
483
+ addItem(value: T, silent?: boolean): void;
484
+
485
+ /**
486
+ * Removes the selected item matching the provided value.
487
+ */
488
+ removeItem(value: T, silent?: boolean): void;
489
+
490
+ /**
491
+ * Invokes the "create" method provided in the selectize options that should provide the data for the
492
+ * new item, given the user input. Once this completes, it will be added to the item list.
493
+ */
494
+ createItem(value: T, triggerDropdown?: boolean, callback?: (data?: any) => void): void;
495
+
496
+ /**
497
+ * Re-renders the selected item lists.
498
+ */
499
+ refreshItems(): void;
500
+
501
+ // Optgroups
502
+ // ------------------------------------------------------------------------------------------------------------
503
+
504
+ /**
505
+ * Registers a new optgroup for options to be bucketed into.
506
+ * The "id" argument refers to a value of the property in option identified by the "optgroupField" setting.
507
+ */
508
+ addOptionGroup(id: string, data: U): void;
509
+
510
+ // Events
511
+ // ------------------------------------------------------------------------------------------------------------
512
+
513
+ /**
514
+ * Adds an event listener.
515
+ */
516
+ on(eventName: string, handler: Function): void;
517
+
518
+ /**
519
+ * Removes an event listener. If no handler is provided, all event listeners are removed.
520
+ */
521
+ off(eventName: string, handler?: Function): void;
522
+
523
+ /**
524
+ * Triggers event listeners.
525
+ */
526
+ trigger(eventName: string, ...args: any[]): void;
527
+
528
+ // Dropdown Actions
529
+ // ------------------------------------------------------------------------------------------------------------
530
+
531
+ /**
532
+ * Shows the autocomplete dropdown containing the available options.
533
+ */
534
+ open(): void;
535
+
536
+ /**
537
+ * Closes the autocomplete dropdown menu.
538
+ */
539
+ close(): void;
540
+
541
+ /**
542
+ * Calculates and applies the appropriate position of the dropdown.
543
+ */
544
+ positionDropdown(): void;
545
+
546
+ // Other
547
+ // ------------------------------------------------------------------------------------------------------------
548
+
549
+ /**
550
+ * Destroys the control and unbinds event listeners so that it can be garbage collected.
551
+ */
552
+ destroy(): void;
553
+
554
+ /**
555
+ * Loads options by invoking the the provided function. The function should accept one argument (callback)
556
+ * and invoke the callback with the results once they are available.
557
+ */
558
+ load(callback: (results: any) => any): void;
559
+
560
+ /**
561
+ * Brings the control into focus.
562
+ */
563
+ focus(): void;
564
+
565
+ /**
566
+ * Forces the control out of focus.
567
+ */
568
+ blur(): void;
569
+
570
+ /**
571
+ * Disables user input on the control (note: the control can still receive focus).
572
+ */
573
+ lock(): void;
574
+
575
+ /**
576
+ * Re-enables user input on the control.
577
+ */
578
+ unlock(): void;
579
+
580
+ /**
581
+ * Disables user input on the control completely. While disabled, it cannot receive focus.
582
+ */
583
+ disable(): void;
584
+
585
+ /**
586
+ * Enables the control so that it can respond to focus and user input.
587
+ */
588
+ enable(): void;
589
+
590
+ /**
591
+ * Returns the value of the control. If multiple items can be selected (e.g. <select multiple>), this
592
+ * returns an array. If only one item can be selected, this returns a string.
593
+ */
594
+ getValue(): any;
595
+
596
+ /**
597
+ * Resets the selected items to the given value(s).
598
+ */
599
+ setValue(value: T, silent?: boolean): void;
600
+ setValue(value: T[], silent?: boolean): void;
601
+
602
+ /**
603
+ * Moves the caret to the specified position ("index" being the index in the list of selected items).
604
+ */
605
+ setCaret(index: number): void;
606
+
607
+ /**
608
+ * Returns whether or not the user can select more items.
609
+ */
610
+ isFull(): boolean;
611
+
612
+ /**
613
+ * Clears the render cache. Takes an optional template argument (e.g. "option", "item") to clear only that cache.
614
+ */
615
+ clearCache(template?: string): void;
616
+
617
+ /**
618
+ * When the `settings.placeholder` value is changed, the new placeholder will be displayed.
619
+ */
620
+ updatePlaceholder(): void;
621
+ }
622
+
623
+ interface ISearchToken {
624
+ regex: RegExp;
625
+ string: string;
626
+ }
627
+
628
+ interface ISearchResult {
629
+ id: string;
630
+ score: number;
631
+ }
632
+
633
+ interface ISearch {
634
+ /**
635
+ * Original search options.
636
+ */
637
+ options: any;
638
+
639
+ /**
640
+ * The raw user input
641
+ */
642
+ query: string;
643
+
644
+ /**
645
+ * An array containing parsed search tokens. A token is an object containing two properties: "string" and "regex".
646
+ */
647
+ tokens: ISearchToken[];
648
+
649
+ /**
650
+ * The total number of results.
651
+ */
652
+ total: number;
653
+
654
+ /**
655
+ * A list of matched results. Each result is an object containing two properties: "score" and "id".
656
+ */
657
+ items: ISearchResult[];
658
+ }
659
+
660
+ // see https://github.com/selectize/selectize.js/blob/master/docs/plugins.md
661
+ interface IPluginOption {
662
+ name: string;
663
+ options: any;
664
+ }
665
+ }
666
+
667
+ interface JQuery {
668
+ selectize(options?: Selectize.IOptions<any, any>): JQuery;
669
+ }
670
+
671
+ interface HTMLElement {
672
+ selectize: Selectize.IApi<any, any>;
673
+ }