@danielgindi/selectbox 1.0.48 → 1.0.51
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 +321 -45
- 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 +68 -41
- 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 +321 -45
- 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 +17 -12
- package/lib/SelectBox.js +50 -28
- package/package.json +15 -14
- package/vue/SelectBox.vue +9 -2
package/dist/lib.es6.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/selectbox 1.0.
|
|
2
|
+
* @danielgindi/selectbox 1.0.51
|
|
3
3
|
* git://github.com/danielgindi/selectbox.git
|
|
4
4
|
*/
|
|
5
5
|
import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
|
|
@@ -51,14 +51,14 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* @typedef {Object} DropList.PositionOptions
|
|
54
|
-
* @property {Element} [target] Target element to act as anchor
|
|
55
|
-
* @property {{left: number, top: number}} [targetOffset
|
|
56
|
-
* @property {number} [targetHeight
|
|
57
|
-
* @property {number} [targetWidth
|
|
58
|
-
* @property {DropList.PositionAnchor} [position
|
|
59
|
-
* @property {DropList.PositionAnchor} [anchor
|
|
60
|
-
* @property {boolean} [updateWidth=false]
|
|
61
|
-
* @property {string} [targetRtl
|
|
54
|
+
* @property {Element?} [target] Target element to act as anchor
|
|
55
|
+
* @property {{left: number, top: number}?} [targetOffset] Override the offset of target. Automatically calculated if unspecified.
|
|
56
|
+
* @property {number?} [targetHeight] Override height of the target
|
|
57
|
+
* @property {number?} [targetWidth] Override width of the target
|
|
58
|
+
* @property {DropList.PositionAnchor?} [position]
|
|
59
|
+
* @property {DropList.PositionAnchor?} [anchor]
|
|
60
|
+
* @property {boolean|number?} [updateWidth=false] `true` to set width of the menu according to `target`'s width, or specify an arbitrary number.
|
|
61
|
+
* @property {string?} [targetRtl] Override for rtl mode of the target
|
|
62
62
|
* @property {{x: number, y: number}} [offset=undefined] Extra rtl-aware offset to the target
|
|
63
63
|
* */
|
|
64
64
|
/** */
|
|
@@ -779,7 +779,7 @@ class DropList {
|
|
|
779
779
|
}
|
|
780
780
|
|
|
781
781
|
// Now set the width of the dropdown
|
|
782
|
-
if (positionOptions.updateWidth) {
|
|
782
|
+
if (positionOptions.updateWidth || typeof positionOptions.updateWidth === 'number') {
|
|
783
783
|
this._updateWidth(positionOptions);
|
|
784
784
|
}
|
|
785
785
|
|
|
@@ -2137,9 +2137,14 @@ class DropList {
|
|
|
2137
2137
|
let targetWidth = 0;
|
|
2138
2138
|
|
|
2139
2139
|
if (positionOptions) {
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2140
|
+
if (typeof positionOptions.updateWidth === 'number') {
|
|
2141
|
+
// Set from width specified
|
|
2142
|
+
targetWidth = positionOptions.updateWidth;
|
|
2143
|
+
} else if (positionOptions.targetWidth != null) {
|
|
2144
|
+
// Set from simulated target width
|
|
2145
|
+
targetWidth = positionOptions.updateWidth;
|
|
2146
|
+
} else {
|
|
2147
|
+
// Measure target
|
|
2143
2148
|
targetWidth = getElementWidth(positionOptions.target, true, true);
|
|
2144
2149
|
}
|
|
2145
2150
|
}
|
|
@@ -3307,27 +3312,11 @@ class SelectBox {
|
|
|
3307
3312
|
* @returns {SelectBox}
|
|
3308
3313
|
*/
|
|
3309
3314
|
clear() {
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
let clearEvt = { cancel: false };
|
|
3313
|
-
this._trigger('clear:before', clearEvt);
|
|
3314
|
-
if (clearEvt.cancel)
|
|
3315
|
+
if (!this._performClearWithEvent(true))
|
|
3315
3316
|
return this;
|
|
3316
3317
|
|
|
3317
|
-
p.selectedItems = [];
|
|
3318
|
-
p.selectedValues = [];
|
|
3319
|
-
p.selectionChanged = true;
|
|
3320
|
-
p.resortBySelectionNeeded = true;
|
|
3321
|
-
|
|
3322
|
-
this._trigger('clear');
|
|
3323
|
-
|
|
3324
3318
|
if (this[DestroyedSymbol]) return this; // destroyed by event handler
|
|
3325
3319
|
|
|
3326
|
-
this._updateListItems();
|
|
3327
|
-
|
|
3328
|
-
this._setInputText('');
|
|
3329
|
-
this._scheduleSync('full');
|
|
3330
|
-
|
|
3331
3320
|
return this;
|
|
3332
3321
|
}
|
|
3333
3322
|
|
|
@@ -3991,19 +3980,11 @@ class SelectBox {
|
|
|
3991
3980
|
const item = event.item;
|
|
3992
3981
|
const value = event.value;
|
|
3993
3982
|
|
|
3994
|
-
|
|
3995
|
-
this._trigger('select:before', selectEvt);
|
|
3996
|
-
|
|
3997
|
-
if (selectEvt.cancel)
|
|
3983
|
+
if (!this._performSelectWithEvent(item, value))
|
|
3998
3984
|
return;
|
|
3999
3985
|
|
|
4000
3986
|
if (this[DestroyedSymbol]) return; // destroyed by event handler
|
|
4001
3987
|
|
|
4002
|
-
this._setSelectedItems([item]);
|
|
4003
|
-
this._trigger('select', { value: value, item: item });
|
|
4004
|
-
|
|
4005
|
-
if (this[DestroyedSymbol]) return; // destroyed by event handler
|
|
4006
|
-
|
|
4007
3988
|
this.closeList();
|
|
4008
3989
|
|
|
4009
3990
|
if (p.blurOnSingleSelection === 'touch' && hasTouchCapability ||
|
|
@@ -4269,6 +4250,40 @@ class SelectBox {
|
|
|
4269
4250
|
});
|
|
4270
4251
|
}
|
|
4271
4252
|
|
|
4253
|
+
_performSelectWithEvent(item, value) {
|
|
4254
|
+
let cancellable = { value: value, item: item, cancel: false };
|
|
4255
|
+
this._trigger('select:before', cancellable);
|
|
4256
|
+
|
|
4257
|
+
if (cancellable.cancel)
|
|
4258
|
+
return false;
|
|
4259
|
+
|
|
4260
|
+
if (this[DestroyedSymbol]) return false; // destroyed by event handler
|
|
4261
|
+
|
|
4262
|
+
this._setSelectedItems([item]);
|
|
4263
|
+
this._trigger('select', { value: value, item: item });
|
|
4264
|
+
|
|
4265
|
+
return true;
|
|
4266
|
+
}
|
|
4267
|
+
|
|
4268
|
+
_performClearWithEvent(clearInput = false) {
|
|
4269
|
+
let cancellable = { cancel: false };
|
|
4270
|
+
this._trigger('clear:before', cancellable);
|
|
4271
|
+
|
|
4272
|
+
if (cancellable.cancel)
|
|
4273
|
+
return false;
|
|
4274
|
+
|
|
4275
|
+
if (this[DestroyedSymbol]) return false; // destroyed by event handler
|
|
4276
|
+
|
|
4277
|
+
this._setSelectedItems([]);
|
|
4278
|
+
|
|
4279
|
+
if (clearInput)
|
|
4280
|
+
this._setInputText('');
|
|
4281
|
+
|
|
4282
|
+
this._trigger('clear');
|
|
4283
|
+
|
|
4284
|
+
return true;
|
|
4285
|
+
}
|
|
4286
|
+
|
|
4272
4287
|
_movePrev() {
|
|
4273
4288
|
const p = this._p;
|
|
4274
4289
|
|
|
@@ -4282,7 +4297,13 @@ class SelectBox {
|
|
|
4282
4297
|
let nextIndex = selectedItems.length > 0 ? items.indexOf(selectedItems[0]) - 1 : (items.length - 1);
|
|
4283
4298
|
if (nextIndex === -1 && !p.clearable)
|
|
4284
4299
|
nextIndex = items.length - 1;
|
|
4285
|
-
|
|
4300
|
+
|
|
4301
|
+
let item = nextIndex === -1 ? null : items[nextIndex];
|
|
4302
|
+
if (item) {
|
|
4303
|
+
this._performSelectWithEvent(item, item[p.valueProp]);
|
|
4304
|
+
} else {
|
|
4305
|
+
this._performClearWithEvent();
|
|
4306
|
+
}
|
|
4286
4307
|
}
|
|
4287
4308
|
}
|
|
4288
4309
|
|
|
@@ -4299,7 +4320,13 @@ class SelectBox {
|
|
|
4299
4320
|
let nextIndex = selectedItems.length > 0 ? items.indexOf(selectedItems[0]) + 1 : 0;
|
|
4300
4321
|
if (nextIndex === items.length)
|
|
4301
4322
|
nextIndex = p.clearable ? -1 : 0;
|
|
4302
|
-
|
|
4323
|
+
|
|
4324
|
+
let item = nextIndex === -1 ? null : items[nextIndex];
|
|
4325
|
+
if (item) {
|
|
4326
|
+
this._performSelectWithEvent(item, item[p.valueProp]);
|
|
4327
|
+
} else {
|
|
4328
|
+
this._performClearWithEvent();
|
|
4329
|
+
}
|
|
4303
4330
|
}
|
|
4304
4331
|
}
|
|
4305
4332
|
|