@danielgindi/selectbox 1.0.49 → 1.0.52
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 +14 -14
- package/vue/SelectBox.vue +5 -0
package/lib/DropList.js
CHANGED
|
@@ -68,14 +68,14 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* @typedef {Object} DropList.PositionOptions
|
|
71
|
-
* @property {Element} [target] Target element to act as anchor
|
|
72
|
-
* @property {{left: number, top: number}} [targetOffset
|
|
73
|
-
* @property {number} [targetHeight
|
|
74
|
-
* @property {number} [targetWidth
|
|
75
|
-
* @property {DropList.PositionAnchor} [position
|
|
76
|
-
* @property {DropList.PositionAnchor} [anchor
|
|
77
|
-
* @property {boolean} [updateWidth=false]
|
|
78
|
-
* @property {string} [targetRtl
|
|
71
|
+
* @property {Element?} [target] Target element to act as anchor
|
|
72
|
+
* @property {{left: number, top: number}?} [targetOffset] Override the offset of target. Automatically calculated if unspecified.
|
|
73
|
+
* @property {number?} [targetHeight] Override height of the target
|
|
74
|
+
* @property {number?} [targetWidth] Override width of the target
|
|
75
|
+
* @property {DropList.PositionAnchor?} [position]
|
|
76
|
+
* @property {DropList.PositionAnchor?} [anchor]
|
|
77
|
+
* @property {boolean|number?} [updateWidth=false] `true` to set width of the menu according to `target`'s width, or specify an arbitrary number.
|
|
78
|
+
* @property {string?} [targetRtl] Override for rtl mode of the target
|
|
79
79
|
* @property {{x: number, y: number}} [offset=undefined] Extra rtl-aware offset to the target
|
|
80
80
|
* */
|
|
81
81
|
/** */
|
|
@@ -796,7 +796,7 @@ class DropList {
|
|
|
796
796
|
}
|
|
797
797
|
|
|
798
798
|
// Now set the width of the dropdown
|
|
799
|
-
if (positionOptions.updateWidth) {
|
|
799
|
+
if (positionOptions.updateWidth || typeof positionOptions.updateWidth === 'number') {
|
|
800
800
|
this._updateWidth(positionOptions);
|
|
801
801
|
}
|
|
802
802
|
|
|
@@ -2154,9 +2154,14 @@ class DropList {
|
|
|
2154
2154
|
let targetWidth = 0;
|
|
2155
2155
|
|
|
2156
2156
|
if (positionOptions) {
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2157
|
+
if (typeof positionOptions.updateWidth === 'number') {
|
|
2158
|
+
// Set from width specified
|
|
2159
|
+
targetWidth = positionOptions.updateWidth;
|
|
2160
|
+
} else if (positionOptions.targetWidth != null) {
|
|
2161
|
+
// Set from simulated target width
|
|
2162
|
+
targetWidth = positionOptions.updateWidth;
|
|
2163
|
+
} else {
|
|
2164
|
+
// Measure target
|
|
2160
2165
|
targetWidth = getElementWidth(positionOptions.target, true, true);
|
|
2161
2166
|
}
|
|
2162
2167
|
}
|
package/lib/SelectBox.js
CHANGED
|
@@ -1124,27 +1124,11 @@ class SelectBox {
|
|
|
1124
1124
|
* @returns {SelectBox}
|
|
1125
1125
|
*/
|
|
1126
1126
|
clear() {
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
let clearEvt = { cancel: false };
|
|
1130
|
-
this._trigger('clear:before', clearEvt);
|
|
1131
|
-
if (clearEvt.cancel)
|
|
1127
|
+
if (!this._performClearWithEvent(true))
|
|
1132
1128
|
return this;
|
|
1133
1129
|
|
|
1134
|
-
p.selectedItems = [];
|
|
1135
|
-
p.selectedValues = [];
|
|
1136
|
-
p.selectionChanged = true;
|
|
1137
|
-
p.resortBySelectionNeeded = true;
|
|
1138
|
-
|
|
1139
|
-
this._trigger('clear');
|
|
1140
|
-
|
|
1141
1130
|
if (this[DestroyedSymbol]) return this; // destroyed by event handler
|
|
1142
1131
|
|
|
1143
|
-
this._updateListItems();
|
|
1144
|
-
|
|
1145
|
-
this._setInputText('');
|
|
1146
|
-
this._scheduleSync('full');
|
|
1147
|
-
|
|
1148
1132
|
return this;
|
|
1149
1133
|
}
|
|
1150
1134
|
|
|
@@ -1808,19 +1792,11 @@ class SelectBox {
|
|
|
1808
1792
|
const item = event.item;
|
|
1809
1793
|
const value = event.value;
|
|
1810
1794
|
|
|
1811
|
-
|
|
1812
|
-
this._trigger('select:before', selectEvt);
|
|
1813
|
-
|
|
1814
|
-
if (selectEvt.cancel)
|
|
1795
|
+
if (!this._performSelectWithEvent(item, value))
|
|
1815
1796
|
return;
|
|
1816
1797
|
|
|
1817
1798
|
if (this[DestroyedSymbol]) return; // destroyed by event handler
|
|
1818
1799
|
|
|
1819
|
-
this._setSelectedItems([item]);
|
|
1820
|
-
this._trigger('select', { value: value, item: item });
|
|
1821
|
-
|
|
1822
|
-
if (this[DestroyedSymbol]) return; // destroyed by event handler
|
|
1823
|
-
|
|
1824
1800
|
this.closeList();
|
|
1825
1801
|
|
|
1826
1802
|
if (p.blurOnSingleSelection === 'touch' && hasTouchCapability ||
|
|
@@ -2086,6 +2062,40 @@ class SelectBox {
|
|
|
2086
2062
|
});
|
|
2087
2063
|
}
|
|
2088
2064
|
|
|
2065
|
+
_performSelectWithEvent(item, value) {
|
|
2066
|
+
let cancellable = { value: value, item: item, cancel: false };
|
|
2067
|
+
this._trigger('select:before', cancellable);
|
|
2068
|
+
|
|
2069
|
+
if (cancellable.cancel)
|
|
2070
|
+
return false;
|
|
2071
|
+
|
|
2072
|
+
if (this[DestroyedSymbol]) return false; // destroyed by event handler
|
|
2073
|
+
|
|
2074
|
+
this._setSelectedItems([item]);
|
|
2075
|
+
this._trigger('select', { value: value, item: item });
|
|
2076
|
+
|
|
2077
|
+
return true;
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
_performClearWithEvent(clearInput = false) {
|
|
2081
|
+
let cancellable = { cancel: false };
|
|
2082
|
+
this._trigger('clear:before', cancellable);
|
|
2083
|
+
|
|
2084
|
+
if (cancellable.cancel)
|
|
2085
|
+
return false;
|
|
2086
|
+
|
|
2087
|
+
if (this[DestroyedSymbol]) return false; // destroyed by event handler
|
|
2088
|
+
|
|
2089
|
+
this._setSelectedItems([]);
|
|
2090
|
+
|
|
2091
|
+
if (clearInput)
|
|
2092
|
+
this._setInputText('');
|
|
2093
|
+
|
|
2094
|
+
this._trigger('clear');
|
|
2095
|
+
|
|
2096
|
+
return true;
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2089
2099
|
_movePrev() {
|
|
2090
2100
|
const p = this._p;
|
|
2091
2101
|
|
|
@@ -2099,7 +2109,13 @@ class SelectBox {
|
|
|
2099
2109
|
let nextIndex = selectedItems.length > 0 ? items.indexOf(selectedItems[0]) - 1 : (items.length - 1);
|
|
2100
2110
|
if (nextIndex === -1 && !p.clearable)
|
|
2101
2111
|
nextIndex = items.length - 1;
|
|
2102
|
-
|
|
2112
|
+
|
|
2113
|
+
let item = nextIndex === -1 ? null : items[nextIndex];
|
|
2114
|
+
if (item) {
|
|
2115
|
+
this._performSelectWithEvent(item, item[p.valueProp]);
|
|
2116
|
+
} else {
|
|
2117
|
+
this._performClearWithEvent();
|
|
2118
|
+
}
|
|
2103
2119
|
}
|
|
2104
2120
|
}
|
|
2105
2121
|
|
|
@@ -2116,7 +2132,13 @@ class SelectBox {
|
|
|
2116
2132
|
let nextIndex = selectedItems.length > 0 ? items.indexOf(selectedItems[0]) + 1 : 0;
|
|
2117
2133
|
if (nextIndex === items.length)
|
|
2118
2134
|
nextIndex = p.clearable ? -1 : 0;
|
|
2119
|
-
|
|
2135
|
+
|
|
2136
|
+
let item = nextIndex === -1 ? null : items[nextIndex];
|
|
2137
|
+
if (item) {
|
|
2138
|
+
this._performSelectWithEvent(item, item[p.valueProp]);
|
|
2139
|
+
} else {
|
|
2140
|
+
this._performClearWithEvent();
|
|
2141
|
+
}
|
|
2120
2142
|
}
|
|
2121
2143
|
}
|
|
2122
2144
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielgindi/selectbox",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.52",
|
|
4
4
|
"description": "A collection of dom utilities. So you can work natively with the dom without dom frameworks.",
|
|
5
5
|
"main": "dist/lib.cjs.min.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -31,25 +31,25 @@
|
|
|
31
31
|
"homepage": "https://github.com/danielgindi/selectbox#readme",
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@babel/core": "^7.
|
|
35
|
-
"@babel/preset-env": "^7.16.
|
|
36
|
-
"@babel/runtime": "^7.
|
|
37
|
-
"@rollup/plugin-babel": "^5.3.
|
|
38
|
-
"@rollup/plugin-commonjs": "^21.0.
|
|
34
|
+
"@babel/core": "^7.17.5",
|
|
35
|
+
"@babel/preset-env": "^7.16.11",
|
|
36
|
+
"@babel/runtime": "^7.17.2",
|
|
37
|
+
"@rollup/plugin-babel": "^5.3.1",
|
|
38
|
+
"@rollup/plugin-commonjs": "^21.0.2",
|
|
39
39
|
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
40
|
-
"core-js": "^3.
|
|
41
|
-
"eslint": "^8.
|
|
40
|
+
"core-js": "^3.21.1",
|
|
41
|
+
"eslint": "^8.10.0",
|
|
42
42
|
"eslint-formatter-codeframe": "^7.32.1",
|
|
43
|
-
"eslint-plugin-vue": "^8.
|
|
44
|
-
"fs-extra": "^10.0.
|
|
43
|
+
"eslint-plugin-vue": "^8.5.0",
|
|
44
|
+
"fs-extra": "^10.0.1",
|
|
45
45
|
"husky": "^7.0.4",
|
|
46
|
-
"pinst": "^
|
|
47
|
-
"rollup": "^2.
|
|
46
|
+
"pinst": "^3.0.0",
|
|
47
|
+
"rollup": "^2.69.1",
|
|
48
48
|
"rollup-plugin-terser": "^7.0.2",
|
|
49
|
-
"sass": "^1.
|
|
49
|
+
"sass": "^1.49.9"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@danielgindi/dom-utils": "^1.0.
|
|
52
|
+
"@danielgindi/dom-utils": "^1.0.7",
|
|
53
53
|
"@danielgindi/virtual-list-helper": "^1.0.3",
|
|
54
54
|
"fast-deep-equal": "^3.1.3",
|
|
55
55
|
"keycode-js": "^3.1.0",
|
package/vue/SelectBox.vue
CHANGED
|
@@ -541,6 +541,11 @@
|
|
|
541
541
|
this._box.setListOptions(this.computedListOptions);
|
|
542
542
|
},
|
|
543
543
|
|
|
544
|
+
filterFn() {
|
|
545
|
+
if (this._box)
|
|
546
|
+
this._box.setFilterFn(this.filterFn);
|
|
547
|
+
},
|
|
548
|
+
|
|
544
549
|
$scopedSlots() {
|
|
545
550
|
if (this._box)
|
|
546
551
|
this._box.setListOptions(this.computedListOptions);
|