@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 CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 1.0.48
2
+ * @danielgindi/selectbox 1.0.51
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  'use strict';
@@ -20,6 +20,251 @@ var DomEventsSink__default = /*#__PURE__*/_interopDefaultLegacy(DomEventsSink);
20
20
  var VirtualListHelper__default = /*#__PURE__*/_interopDefaultLegacy(VirtualListHelper);
21
21
  var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
22
22
 
23
+ function createMetadataMethodsForProperty(metadataMap, kind, property) {
24
+ return {
25
+ getMetadata: function (key) {
26
+ if ("symbol" != typeof key) throw new TypeError("Metadata keys must be symbols, received: " + key);
27
+ var metadataForKey = metadataMap[key];
28
+ if (void 0 !== metadataForKey) if (1 === kind) {
29
+ var pub = metadataForKey.public;
30
+ if (void 0 !== pub) return pub[property];
31
+ } else if (2 === kind) {
32
+ var priv = metadataForKey.private;
33
+ if (void 0 !== priv) return priv.get(property);
34
+ } else if (Object.hasOwnProperty.call(metadataForKey, "constructor")) return metadataForKey.constructor;
35
+ },
36
+ setMetadata: function (key, value) {
37
+ if ("symbol" != typeof key) throw new TypeError("Metadata keys must be symbols, received: " + key);
38
+ var metadataForKey = metadataMap[key];
39
+
40
+ if (void 0 === metadataForKey && (metadataForKey = metadataMap[key] = {}), 1 === kind) {
41
+ var pub = metadataForKey.public;
42
+ void 0 === pub && (pub = metadataForKey.public = {}), pub[property] = value;
43
+ } else if (2 === kind) {
44
+ var priv = metadataForKey.priv;
45
+ void 0 === priv && (priv = metadataForKey.private = new Map()), priv.set(property, value);
46
+ } else metadataForKey.constructor = value;
47
+ }
48
+ };
49
+ }
50
+
51
+ function convertMetadataMapToFinal(obj, metadataMap) {
52
+ var parentMetadataMap = obj[Symbol.metadata || Symbol.for("Symbol.metadata")],
53
+ metadataKeys = Object.getOwnPropertySymbols(metadataMap);
54
+
55
+ if (0 !== metadataKeys.length) {
56
+ for (var i = 0; i < metadataKeys.length; i++) {
57
+ var key = metadataKeys[i],
58
+ metaForKey = metadataMap[key],
59
+ parentMetaForKey = parentMetadataMap ? parentMetadataMap[key] : null,
60
+ pub = metaForKey.public,
61
+ parentPub = parentMetaForKey ? parentMetaForKey.public : null;
62
+ pub && parentPub && Object.setPrototypeOf(pub, parentPub);
63
+ var priv = metaForKey.private;
64
+
65
+ if (priv) {
66
+ var privArr = Array.from(priv.values()),
67
+ parentPriv = parentMetaForKey ? parentMetaForKey.private : null;
68
+ parentPriv && (privArr = privArr.concat(parentPriv)), metaForKey.private = privArr;
69
+ }
70
+
71
+ parentMetaForKey && Object.setPrototypeOf(metaForKey, parentMetaForKey);
72
+ }
73
+
74
+ parentMetadataMap && Object.setPrototypeOf(metadataMap, parentMetadataMap), obj[Symbol.metadata || Symbol.for("Symbol.metadata")] = metadataMap;
75
+ }
76
+ }
77
+
78
+ function createAddInitializerMethod(initializers) {
79
+ return function (initializer) {
80
+ assertValidInitializer(initializer), initializers.push(initializer);
81
+ };
82
+ }
83
+
84
+ function memberDecCtx(base, name, desc, metadataMap, initializers, kind, isStatic, isPrivate) {
85
+ var kindStr;
86
+
87
+ switch (kind) {
88
+ case 1:
89
+ kindStr = "accessor";
90
+ break;
91
+
92
+ case 2:
93
+ kindStr = "method";
94
+ break;
95
+
96
+ case 3:
97
+ kindStr = "getter";
98
+ break;
99
+
100
+ case 4:
101
+ kindStr = "setter";
102
+ break;
103
+
104
+ default:
105
+ kindStr = "field";
106
+ }
107
+
108
+ var metadataKind,
109
+ metadataName,
110
+ ctx = {
111
+ kind: kindStr,
112
+ name: isPrivate ? "#" + name : name,
113
+ isStatic: isStatic,
114
+ isPrivate: isPrivate
115
+ };
116
+
117
+ if (0 !== kind && (ctx.addInitializer = createAddInitializerMethod(initializers)), isPrivate) {
118
+ metadataKind = 2, metadataName = Symbol(name);
119
+ var access = {};
120
+ 0 === kind ? (access.get = desc.get, access.set = desc.set) : 2 === kind ? access.get = function () {
121
+ return desc.value;
122
+ } : (1 !== kind && 3 !== kind || (access.get = function () {
123
+ return desc.get.call(this);
124
+ }), 1 !== kind && 4 !== kind || (access.set = function (v) {
125
+ desc.set.call(this, v);
126
+ })), ctx.access = access;
127
+ } else metadataKind = 1, metadataName = name;
128
+
129
+ return Object.assign(ctx, createMetadataMethodsForProperty(metadataMap, metadataKind, metadataName));
130
+ }
131
+
132
+ function assertValidInitializer(initializer) {
133
+ if ("function" != typeof initializer) throw new Error("initializers must be functions");
134
+ }
135
+
136
+ function assertValidReturnValue(kind, value) {
137
+ var type = typeof value;
138
+
139
+ if (1 === kind) {
140
+ if ("object" !== type || null === value) throw new Error("accessor decorators must return an object with get, set, or initializer properties or void 0");
141
+ } else if ("function" !== type) throw 0 === kind ? new Error("field decorators must return a initializer function or void 0") : new Error("method decorators must return a function or void 0");
142
+ }
143
+
144
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, metadataMap, initializers) {
145
+ var desc,
146
+ initializer,
147
+ value,
148
+ decs = decInfo[0];
149
+ isPrivate ? desc = 0 === kind || 1 === kind ? {
150
+ get: decInfo[3],
151
+ set: decInfo[4]
152
+ } : 3 === kind ? {
153
+ get: decInfo[3]
154
+ } : 4 === kind ? {
155
+ set: decInfo[3]
156
+ } : {
157
+ value: decInfo[3]
158
+ } : 0 !== kind && (desc = Object.getOwnPropertyDescriptor(base, name)), 1 === kind ? value = {
159
+ get: desc.get,
160
+ set: desc.set
161
+ } : 2 === kind ? value = desc.value : 3 === kind ? value = desc.get : 4 === kind && (value = desc.set);
162
+ var newValue,
163
+ get,
164
+ set,
165
+ ctx = memberDecCtx(base, name, desc, metadataMap, initializers, kind, isStatic, isPrivate);
166
+ if ("function" == typeof decs) void 0 !== (newValue = decs(value, ctx)) && (assertValidReturnValue(kind, newValue), 0 === kind ? initializer = newValue : 1 === kind ? (initializer = newValue.initializer, get = newValue.get || value.get, set = newValue.set || value.set, value = {
167
+ get: get,
168
+ set: set
169
+ }) : value = newValue);else for (var i = decs.length - 1; i >= 0; i--) {
170
+ var newInit;
171
+ if (void 0 !== (newValue = (0, decs[i])(value, ctx))) assertValidReturnValue(kind, newValue), 0 === kind ? newInit = newValue : 1 === kind ? (newInit = newValue.initializer, get = newValue.get || value.get, set = newValue.set || value.set, value = {
172
+ get: get,
173
+ set: set
174
+ }) : value = newValue, void 0 !== newInit && (void 0 === initializer ? initializer = newInit : "function" == typeof initializer ? initializer = [initializer, newInit] : initializer.push(newInit));
175
+ }
176
+
177
+ if (0 === kind || 1 === kind) {
178
+ if (void 0 === initializer) initializer = function (instance, init) {
179
+ return init;
180
+ };else if ("function" != typeof initializer) {
181
+ var ownInitializers = initializer;
182
+
183
+ initializer = function (instance, init) {
184
+ for (var value = init, i = 0; i < ownInitializers.length; i++) value = ownInitializers[i].call(instance, value);
185
+
186
+ return value;
187
+ };
188
+ } else {
189
+ var originalInitializer = initializer;
190
+
191
+ initializer = function (instance, init) {
192
+ return originalInitializer.call(instance, init);
193
+ };
194
+ }
195
+ ret.push(initializer);
196
+ }
197
+
198
+ 0 !== kind && (1 === kind ? (desc.get = value.get, desc.set = value.set) : 2 === kind ? desc.value = value : 3 === kind ? desc.get = value : 4 === kind && (desc.set = value), isPrivate ? 1 === kind ? (ret.push(function (instance, args) {
199
+ return value.get.call(instance, args);
200
+ }), ret.push(function (instance, args) {
201
+ return value.set.call(instance, args);
202
+ })) : 2 === kind ? ret.push(value) : ret.push(function (instance, args) {
203
+ return value.call(instance, args);
204
+ }) : Object.defineProperty(base, name, desc));
205
+ }
206
+
207
+ function applyMemberDecs(ret, Class, protoMetadataMap, staticMetadataMap, decInfos) {
208
+ for (var protoInitializers = [], staticInitializers = [], existingProtoNonFields = new Map(), existingStaticNonFields = new Map(), i = 0; i < decInfos.length; i++) {
209
+ var decInfo = decInfos[i];
210
+
211
+ if (Array.isArray(decInfo)) {
212
+ var base,
213
+ metadataMap,
214
+ initializers,
215
+ kind = decInfo[1],
216
+ name = decInfo[2],
217
+ isPrivate = decInfo.length > 3,
218
+ isStatic = kind >= 5;
219
+
220
+ if (isStatic ? (base = Class, metadataMap = staticMetadataMap, kind -= 5, initializers = staticInitializers) : (base = Class.prototype, metadataMap = protoMetadataMap, initializers = protoInitializers), 0 !== kind && !isPrivate) {
221
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields,
222
+ existingKind = existingNonFields.get(name) || 0;
223
+ if (!0 === existingKind || 3 === existingKind && 4 !== kind || 4 === existingKind && 3 !== kind) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
224
+ !existingKind && kind > 2 ? existingNonFields.set(name, kind) : existingNonFields.set(name, !0);
225
+ }
226
+
227
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, metadataMap, initializers);
228
+ }
229
+ }
230
+
231
+ protoInitializers.length > 0 && pushInitializers(ret, protoInitializers), staticInitializers.length > 0 && pushInitializers(ret, staticInitializers);
232
+ }
233
+
234
+ function pushInitializers(ret, initializers) {
235
+ initializers.length > 0 ? (initializers = initializers.slice(), ret.push(function (instance) {
236
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(instance, instance);
237
+
238
+ return instance;
239
+ })) : ret.push(function (instance) {
240
+ return instance;
241
+ });
242
+ }
243
+
244
+ function applyClassDecs(ret, targetClass, metadataMap, classDecs) {
245
+ for (var initializers = [], newClass = targetClass, name = targetClass.name, ctx = Object.assign({
246
+ kind: "class",
247
+ name: name,
248
+ addInitializer: createAddInitializerMethod(initializers)
249
+ }, createMetadataMethodsForProperty(metadataMap, 0, name)), i = classDecs.length - 1; i >= 0; i--) newClass = classDecs[i](newClass, ctx) || newClass;
250
+
251
+ ret.push(newClass), initializers.length > 0 ? ret.push(function () {
252
+ for (var i = 0; i < initializers.length; i++) initializers[i].call(newClass, newClass);
253
+ }) : ret.push(function () {});
254
+ }
255
+
256
+ function _applyDecs(targetClass, memberDecs, classDecs) {
257
+ var ret = [],
258
+ staticMetadataMap = {};
259
+
260
+ if (memberDecs) {
261
+ var protoMetadataMap = {};
262
+ applyMemberDecs(ret, targetClass, protoMetadataMap, staticMetadataMap, memberDecs), convertMetadataMapToFinal(targetClass.prototype, protoMetadataMap);
263
+ }
264
+
265
+ return classDecs && applyClassDecs(ret, targetClass, staticMetadataMap, classDecs), convertMetadataMapToFinal(targetClass, staticMetadataMap), ret;
266
+ }
267
+
23
268
  function _asyncIterator(iterable) {
24
269
  var method,
25
270
  async,
@@ -1684,6 +1929,10 @@ function _classPrivateMethodSet() {
1684
1929
  throw new TypeError("attempted to reassign private method");
1685
1930
  }
1686
1931
 
1932
+ function _identity(x) {
1933
+ return x;
1934
+ }
1935
+
1687
1936
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
1688
1937
 
1689
1938
  function getDefaultExportFromCjs (x) {
@@ -2032,10 +2281,10 @@ var store$2 = sharedStore;
2032
2281
  (shared$6.exports = function (key, value) {
2033
2282
  return store$2[key] || (store$2[key] = value !== undefined ? value : {});
2034
2283
  })('versions', []).push({
2035
- version: '3.20.3',
2284
+ version: '3.21.1',
2036
2285
  mode: IS_PURE$5 ? 'pure' : 'global',
2037
2286
  copyright: '© 2014-2022 Denis Pushkarev (zloirock.ru)',
2038
- license: 'https://github.com/zloirock/core-js/blob/v3.20.3/LICENSE',
2287
+ license: 'https://github.com/zloirock/core-js/blob/v3.21.1/LICENSE',
2039
2288
  source: 'https://github.com/zloirock/core-js'
2040
2289
  });
2041
2290
 
@@ -4247,8 +4496,8 @@ var fails$e = fails$v;
4247
4496
  var arrayMethodIsStrict$4 = function (METHOD_NAME, argument) {
4248
4497
  var method = [][METHOD_NAME];
4249
4498
  return !!method && fails$e(function () {
4250
- // eslint-disable-next-line no-useless-call,no-throw-literal -- required for testing
4251
- method.call(null, argument || function () { throw 1; }, 1);
4499
+ // eslint-disable-next-line no-useless-call -- required for testing
4500
+ method.call(null, argument || function () { return 1; }, 1);
4252
4501
  });
4253
4502
  };
4254
4503
 
@@ -5634,14 +5883,14 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;
5634
5883
 
5635
5884
  /**
5636
5885
  * @typedef {Object} DropList.PositionOptions
5637
- * @property {Element} [target] Target element to act as anchor
5638
- * @property {{left: number, top: number}} [targetOffset=undefined] Override the offset of target. Automatically calculated if unspecified.
5639
- * @property {number} [targetHeight=undefined] Override height of the target
5640
- * @property {number} [targetWidth=undefined] Override width of the target
5641
- * @property {DropList.PositionAnchor} [position=undefined]
5642
- * @property {DropList.PositionAnchor} [anchor=undefined]
5643
- * @property {boolean} [updateWidth=false] Should update the width of the menu according to target
5644
- * @property {string} [targetRtl=undefined] Override for rtl mode of the target
5886
+ * @property {Element?} [target] Target element to act as anchor
5887
+ * @property {{left: number, top: number}?} [targetOffset] Override the offset of target. Automatically calculated if unspecified.
5888
+ * @property {number?} [targetHeight] Override height of the target
5889
+ * @property {number?} [targetWidth] Override width of the target
5890
+ * @property {DropList.PositionAnchor?} [position]
5891
+ * @property {DropList.PositionAnchor?} [anchor]
5892
+ * @property {boolean|number?} [updateWidth=false] `true` to set width of the menu according to `target`'s width, or specify an arbitrary number.
5893
+ * @property {string?} [targetRtl] Override for rtl mode of the target
5645
5894
  * @property {{x: number, y: number}} [offset=undefined] Extra rtl-aware offset to the target
5646
5895
  * */
5647
5896
  /** */
@@ -6362,7 +6611,7 @@ var DropList = /*#__PURE__*/function () {
6362
6611
  }
6363
6612
 
6364
6613
  // Now set the width of the dropdown
6365
- if (positionOptions.updateWidth) {
6614
+ if (positionOptions.updateWidth || typeof positionOptions.updateWidth === 'number') {
6366
6615
  this._updateWidth(positionOptions);
6367
6616
  }
6368
6617
 
@@ -7720,9 +7969,14 @@ var DropList = /*#__PURE__*/function () {
7720
7969
  var targetWidth = 0;
7721
7970
 
7722
7971
  if (positionOptions) {
7723
- // Measure target
7724
- targetWidth = positionOptions.targetWidth;
7725
- if (targetWidth == null) {
7972
+ if (typeof positionOptions.updateWidth === 'number') {
7973
+ // Set from width specified
7974
+ targetWidth = positionOptions.updateWidth;
7975
+ } else if (positionOptions.targetWidth != null) {
7976
+ // Set from simulated target width
7977
+ targetWidth = positionOptions.updateWidth;
7978
+ } else {
7979
+ // Measure target
7726
7980
  targetWidth = Css.getElementWidth(positionOptions.target, true, true);
7727
7981
  }
7728
7982
  }
@@ -9919,27 +10173,11 @@ var SelectBox = /*#__PURE__*/function () {
9919
10173
  * @returns {SelectBox}
9920
10174
  */ }, { key: "clear", value:
9921
10175
  function clear() {
9922
- var p = this._p;
9923
-
9924
- var clearEvt = { cancel: false };
9925
- this._trigger('clear:before', clearEvt);
9926
- if (clearEvt.cancel)
10176
+ if (!this._performClearWithEvent(true))
9927
10177
  return this;
9928
10178
 
9929
- p.selectedItems = [];
9930
- p.selectedValues = [];
9931
- p.selectionChanged = true;
9932
- p.resortBySelectionNeeded = true;
9933
-
9934
- this._trigger('clear');
9935
-
9936
10179
  if (this[DestroyedSymbol]) return this; // destroyed by event handler
9937
10180
 
9938
- this._updateListItems();
9939
-
9940
- this._setInputText('');
9941
- this._scheduleSync('full');
9942
-
9943
10181
  return this;
9944
10182
  }
9945
10183
 
@@ -10603,19 +10841,11 @@ var SelectBox = /*#__PURE__*/function () {
10603
10841
  var _item = event.item;
10604
10842
  var _value = event.value;
10605
10843
 
10606
- var selectEvt = { value: _value, item: _item, cancel: false };
10607
- _this5._trigger('select:before', selectEvt);
10608
-
10609
- if (selectEvt.cancel)
10844
+ if (!_this5._performSelectWithEvent(_item, _value))
10610
10845
  return;
10611
10846
 
10612
10847
  if (_this5[DestroyedSymbol]) return; // destroyed by event handler
10613
10848
 
10614
- _this5._setSelectedItems([_item]);
10615
- _this5._trigger('select', { value: _value, item: _item });
10616
-
10617
- if (_this5[DestroyedSymbol]) return; // destroyed by event handler
10618
-
10619
10849
  _this5.closeList();
10620
10850
 
10621
10851
  if (p.blurOnSingleSelection === 'touch' && hasTouchCapability ||
@@ -10879,6 +11109,40 @@ var SelectBox = /*#__PURE__*/function () {
10879
11109
  }).
10880
11110
  add(p.el, 'touchcancel.dropdown_touchextra', onTouchCancel);
10881
11111
  });
11112
+ } }, { key: "_performSelectWithEvent", value:
11113
+
11114
+ function _performSelectWithEvent(item, value) {
11115
+ var cancellable = { value: value, item: item, cancel: false };
11116
+ this._trigger('select:before', cancellable);
11117
+
11118
+ if (cancellable.cancel)
11119
+ return false;
11120
+
11121
+ if (this[DestroyedSymbol]) return false; // destroyed by event handler
11122
+
11123
+ this._setSelectedItems([item]);
11124
+ this._trigger('select', { value: value, item: item });
11125
+
11126
+ return true;
11127
+ } }, { key: "_performClearWithEvent", value:
11128
+
11129
+ function _performClearWithEvent() {var clearInput = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
11130
+ var cancellable = { cancel: false };
11131
+ this._trigger('clear:before', cancellable);
11132
+
11133
+ if (cancellable.cancel)
11134
+ return false;
11135
+
11136
+ if (this[DestroyedSymbol]) return false; // destroyed by event handler
11137
+
11138
+ this._setSelectedItems([]);
11139
+
11140
+ if (clearInput)
11141
+ this._setInputText('');
11142
+
11143
+ this._trigger('clear');
11144
+
11145
+ return true;
10882
11146
  } }, { key: "_movePrev", value:
10883
11147
 
10884
11148
  function _movePrev() {var _p$filteredItems;
@@ -10894,7 +11158,13 @@ var SelectBox = /*#__PURE__*/function () {
10894
11158
  var nextIndex = selectedItems.length > 0 ? items.indexOf(selectedItems[0]) - 1 : items.length - 1;
10895
11159
  if (nextIndex === -1 && !p.clearable)
10896
11160
  nextIndex = items.length - 1;
10897
- this.setSelectedItems(nextIndex === -1 ? [] : [items[nextIndex]]);
11161
+
11162
+ var item = nextIndex === -1 ? null : items[nextIndex];
11163
+ if (item) {
11164
+ this._performSelectWithEvent(item, item[p.valueProp]);
11165
+ } else {
11166
+ this._performClearWithEvent();
11167
+ }
10898
11168
  }
10899
11169
  } }, { key: "_moveNext", value:
10900
11170
 
@@ -10911,7 +11181,13 @@ var SelectBox = /*#__PURE__*/function () {
10911
11181
  var nextIndex = selectedItems.length > 0 ? items.indexOf(selectedItems[0]) + 1 : 0;
10912
11182
  if (nextIndex === items.length)
10913
11183
  nextIndex = p.clearable ? -1 : 0;
10914
- this.setSelectedItems(nextIndex === -1 ? [] : [items[nextIndex]]);
11184
+
11185
+ var item = nextIndex === -1 ? null : items[nextIndex];
11186
+ if (item) {
11187
+ this._performSelectWithEvent(item, item[p.valueProp]);
11188
+ } else {
11189
+ this._performClearWithEvent();
11190
+ }
10915
11191
  }
10916
11192
  }
10917
11193