@danielgindi/selectbox 1.0.32 → 1.0.33
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.
- package/dist/lib.cjs.js +892 -763
- package/dist/lib.cjs.js.map +1 -1
- package/dist/lib.cjs.min.js +2 -2
- package/dist/lib.cjs.min.js.map +1 -1
- package/dist/lib.es6.js +123 -12
- package/dist/lib.es6.js.map +1 -1
- package/dist/lib.es6.min.js +2 -2
- package/dist/lib.es6.min.js.map +1 -1
- package/dist/lib.umd.js +896 -767
- package/dist/lib.umd.js.map +1 -1
- package/dist/lib.umd.min.js +2 -2
- package/dist/lib.umd.min.js.map +1 -1
- package/lib/DropList.js +64 -6
- package/lib/SelectBox.js +59 -4
- package/package.json +11 -11
package/dist/lib.es6.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/selectbox 1.0.
|
|
2
|
+
* @danielgindi/selectbox 1.0.33
|
|
3
3
|
* git://github.com/danielgindi/selectbox.git
|
|
4
4
|
*/
|
|
5
5
|
import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
|
|
6
6
|
import { remove, toggleClass, before, append, getRootNode } from '@danielgindi/dom-utils/lib/DomCompat';
|
|
7
|
-
import { setCssProps, getElementOffset, getElementHeight, getElementWidth, anchoredPosition, setElementHeight, setElementWidth, getPseudoElementWidth, getCssProps } from '@danielgindi/dom-utils/lib/Css';
|
|
7
|
+
import { setCssProps, getElementOffset, getElementHeight, getElementWidth, anchoredPosition, setElementHeight, parseTransition, setElementWidth, getPseudoElementWidth, getCssProps } from '@danielgindi/dom-utils/lib/Css';
|
|
8
8
|
import DomEventsSink from '@danielgindi/dom-utils/lib/DomEventsSink';
|
|
9
9
|
import VirtualListHelper from '@danielgindi/virtual-list-helper';
|
|
10
|
-
import parseCssTransition from 'parse-css-transition';
|
|
11
10
|
import { VALUE_ESCAPE, VALUE_SPACE, VALUE_ENTER, VALUE_DOWN, VALUE_UP, VALUE_END, VALUE_HOME, VALUE_PAGE_DOWN, VALUE_PAGE_UP, VALUE_TAB, VALUE_DELETE, VALUE_BACK_SPACE, VALUE_LEFT, VALUE_RIGHT } from 'keycode-js';
|
|
11
|
+
import mitt from 'mitt';
|
|
12
12
|
|
|
13
13
|
var escapeRegex = value => value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
14
14
|
|
|
@@ -106,7 +106,7 @@ let defaultOptions$1 = {
|
|
|
106
106
|
Emits the following events:
|
|
107
107
|
---------------------------
|
|
108
108
|
|
|
109
|
-
'itemfocus' {value, item}: item gained focus.
|
|
109
|
+
'itemfocus' {value, item, event}: item gained focus.
|
|
110
110
|
'itemblur' {value, item}: item lost focus.
|
|
111
111
|
'select' {value, item}: item was selected (in single mode).
|
|
112
112
|
'show:before': the drop list will show.
|
|
@@ -151,7 +151,9 @@ class DropList {
|
|
|
151
151
|
valueProp: o.valueProp,
|
|
152
152
|
renderItem: o.renderItem,
|
|
153
153
|
unrenderItem: o.unrenderItem,
|
|
154
|
-
on: o.on,
|
|
154
|
+
on: o.on || null,
|
|
155
|
+
silenceEvents: true,
|
|
156
|
+
mitt: mitt(),
|
|
155
157
|
|
|
156
158
|
focusItemIndex: -1,
|
|
157
159
|
focusItemEl: null,
|
|
@@ -290,6 +292,8 @@ class DropList {
|
|
|
290
292
|
this._hookTouchEvents();
|
|
291
293
|
this._hookFocusEvents();
|
|
292
294
|
this._hookKeyEvents();
|
|
295
|
+
|
|
296
|
+
this.silenceEvents = false;
|
|
293
297
|
}
|
|
294
298
|
|
|
295
299
|
destroy() {
|
|
@@ -1114,7 +1118,7 @@ class DropList {
|
|
|
1114
1118
|
el.classList.add(`${p.baseClassName}__is-hiding`);
|
|
1115
1119
|
|
|
1116
1120
|
// support for hide transition in css
|
|
1117
|
-
const maxTransitionDuration =
|
|
1121
|
+
const maxTransitionDuration = parseTransition(getComputedStyle(p.el).transition)
|
|
1118
1122
|
.reduce((p, v) => Math.max(p, v.delay + v.duration), 0);
|
|
1119
1123
|
|
|
1120
1124
|
if (maxTransitionDuration > 0) {
|
|
@@ -1196,7 +1200,7 @@ class DropList {
|
|
|
1196
1200
|
itemElement.classList.add(`${p.baseClassName}__item_focus`);
|
|
1197
1201
|
p.focusItemEl = itemElement;
|
|
1198
1202
|
|
|
1199
|
-
this._trigger('itemfocus', { value: itemElement[p.valueProp], item: itemElement[ItemSymbol$1] });
|
|
1203
|
+
this._trigger('itemfocus', { value: itemElement[p.valueProp], item: itemElement[ItemSymbol$1], event: null });
|
|
1200
1204
|
}
|
|
1201
1205
|
}
|
|
1202
1206
|
|
|
@@ -1300,6 +1304,58 @@ class DropList {
|
|
|
1300
1304
|
return this;
|
|
1301
1305
|
}
|
|
1302
1306
|
|
|
1307
|
+
/**
|
|
1308
|
+
* Register an event handler
|
|
1309
|
+
* @param {(string|'*')?} event
|
|
1310
|
+
* @param {function(any)} handler
|
|
1311
|
+
* @returns {DropList}
|
|
1312
|
+
*/
|
|
1313
|
+
on(/**string|'*'*/event, /**Function?*/handler) {
|
|
1314
|
+
this._p.mitt.on(event, handler);
|
|
1315
|
+
return this;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
/**
|
|
1319
|
+
* Register a one time event handler
|
|
1320
|
+
* @param {(string|'*')?} event
|
|
1321
|
+
* @param {function(any)} handler
|
|
1322
|
+
* @returns {DropList}
|
|
1323
|
+
*/
|
|
1324
|
+
once(/**string|'*'*/event, /**Function?*/handler) {
|
|
1325
|
+
let wrapped = (value) => {
|
|
1326
|
+
this._p.mitt.off(event, wrapped);
|
|
1327
|
+
handler(value);
|
|
1328
|
+
};
|
|
1329
|
+
this._p.mitt.on(event, wrapped);
|
|
1330
|
+
return this;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
/**
|
|
1334
|
+
* Remove an `handler` for `event`, all events for `event`, or all events completely.
|
|
1335
|
+
* @param {(string|'*')?} event
|
|
1336
|
+
* @param {function(any)} handler
|
|
1337
|
+
* @returns {DropList}
|
|
1338
|
+
*/
|
|
1339
|
+
off(/**(string|'*')?*/event, /**Function?*/handler) {
|
|
1340
|
+
if (!event && !event) {
|
|
1341
|
+
this._p.mitt.all.clear();
|
|
1342
|
+
} else {
|
|
1343
|
+
this._p.mitt.off(event, handler);
|
|
1344
|
+
}
|
|
1345
|
+
return this;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* Emit an event
|
|
1350
|
+
* @param {string} event
|
|
1351
|
+
* @param {any} value
|
|
1352
|
+
* @returns {DropList}
|
|
1353
|
+
*/
|
|
1354
|
+
emit(/**string|'*'*/event, /**any?*/value) {
|
|
1355
|
+
this._p.mitt.emit(event, value);
|
|
1356
|
+
return this;
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1303
1359
|
_getItemIndex(item) {
|
|
1304
1360
|
const p = this._p, labelProp = p.labelProp, valueProp = p.valueProp;
|
|
1305
1361
|
|
|
@@ -1342,6 +1398,7 @@ class DropList {
|
|
|
1342
1398
|
const p = this._p;
|
|
1343
1399
|
if (p.on)
|
|
1344
1400
|
p.on(event, ...(data === undefined ? [] : [data]));
|
|
1401
|
+
p.mitt.emit(event, data);
|
|
1345
1402
|
}
|
|
1346
1403
|
|
|
1347
1404
|
_itemUpAction(event, itemEl) {
|
|
@@ -1645,7 +1702,7 @@ class DropList {
|
|
|
1645
1702
|
p.focusItemIndex = itemIndex;
|
|
1646
1703
|
|
|
1647
1704
|
const item = p.items[itemIndex];
|
|
1648
|
-
this._trigger('itemfocus', { value: item[p.valueProp], item: item });
|
|
1705
|
+
this._trigger('itemfocus', { value: item[p.valueProp], item: item, event: event });
|
|
1649
1706
|
}
|
|
1650
1707
|
} else {
|
|
1651
1708
|
// This could happen if trying to focus a grouped item
|
|
@@ -2306,7 +2363,9 @@ class SelectBox {
|
|
|
2306
2363
|
renderNoResultsItem: o.renderNoResultsItem,
|
|
2307
2364
|
unrenderNoResultsItem: o.unrenderNoResultsItem,
|
|
2308
2365
|
filterFn: o.filterFn,
|
|
2309
|
-
on: null,
|
|
2366
|
+
on: o.on || null,
|
|
2367
|
+
silenceEvents: true,
|
|
2368
|
+
mitt: mitt(),
|
|
2310
2369
|
additionalClasses: o.additionalClasses,
|
|
2311
2370
|
|
|
2312
2371
|
isLoadingMode: !!o.isLoadingMode,
|
|
@@ -2413,11 +2472,10 @@ class SelectBox {
|
|
|
2413
2472
|
this.setValue(o.value);
|
|
2414
2473
|
}
|
|
2415
2474
|
|
|
2416
|
-
// Start firing events
|
|
2417
|
-
p.on = o.on || null;
|
|
2418
|
-
|
|
2419
2475
|
this._scheduleSync();
|
|
2420
2476
|
|
|
2477
|
+
this.silenceEvents = false;
|
|
2478
|
+
|
|
2421
2479
|
return this;
|
|
2422
2480
|
}
|
|
2423
2481
|
|
|
@@ -3427,6 +3485,58 @@ class SelectBox {
|
|
|
3427
3485
|
return this;
|
|
3428
3486
|
}
|
|
3429
3487
|
|
|
3488
|
+
/**
|
|
3489
|
+
* Register an event handler
|
|
3490
|
+
* @param {(string|'*')?} event
|
|
3491
|
+
* @param {function(any)} handler
|
|
3492
|
+
* @returns {SelectBox}
|
|
3493
|
+
*/
|
|
3494
|
+
on(/**string|'*'*/event, /**Function?*/handler) {
|
|
3495
|
+
this._p.mitt.on(event, handler);
|
|
3496
|
+
return this;
|
|
3497
|
+
}
|
|
3498
|
+
|
|
3499
|
+
/**
|
|
3500
|
+
* Register a one time event handler
|
|
3501
|
+
* @param {(string|'*')?} event
|
|
3502
|
+
* @param {function(any)} handler
|
|
3503
|
+
* @returns {SelectBox}
|
|
3504
|
+
*/
|
|
3505
|
+
once(/**string|'*'*/event, /**Function?*/handler) {
|
|
3506
|
+
let wrapped = (value) => {
|
|
3507
|
+
this._p.mitt.off(event, wrapped);
|
|
3508
|
+
handler(value);
|
|
3509
|
+
};
|
|
3510
|
+
this._p.mitt.on(event, wrapped);
|
|
3511
|
+
return this;
|
|
3512
|
+
}
|
|
3513
|
+
|
|
3514
|
+
/**
|
|
3515
|
+
* Remove an `handler` for `event`, all events for `event`, or all events completely.
|
|
3516
|
+
* @param {(string|'*')?} event
|
|
3517
|
+
* @param {function(any)} handler
|
|
3518
|
+
* @returns {SelectBox}
|
|
3519
|
+
*/
|
|
3520
|
+
off(/**(string|'*')?*/event, /**Function?*/handler) {
|
|
3521
|
+
if (!event && !event) {
|
|
3522
|
+
this._p.mitt.all.clear();
|
|
3523
|
+
} else {
|
|
3524
|
+
this._p.mitt.off(event, handler);
|
|
3525
|
+
}
|
|
3526
|
+
return this;
|
|
3527
|
+
}
|
|
3528
|
+
|
|
3529
|
+
/**
|
|
3530
|
+
* Emit an event
|
|
3531
|
+
* @param {string} event
|
|
3532
|
+
* @param {any} value
|
|
3533
|
+
* @returns {SelectBox}
|
|
3534
|
+
*/
|
|
3535
|
+
emit(/**string|'*'*/event, /**any?*/value) {
|
|
3536
|
+
this._p.mitt.emit(event, value);
|
|
3537
|
+
return this;
|
|
3538
|
+
}
|
|
3539
|
+
|
|
3430
3540
|
/** @private */
|
|
3431
3541
|
_renderBase() {
|
|
3432
3542
|
const p = this._p;
|
|
@@ -4601,6 +4711,7 @@ class SelectBox {
|
|
|
4601
4711
|
const p = this._p;
|
|
4602
4712
|
if (p.on)
|
|
4603
4713
|
p.on(event, ...(data === undefined ? [] : [data]));
|
|
4714
|
+
p.mitt.emit(event, data);
|
|
4604
4715
|
}
|
|
4605
4716
|
|
|
4606
4717
|
/**
|