@danielgindi/selectbox 1.0.141 → 1.0.142

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.141
2
+ * @danielgindi/selectbox 1.0.142
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  'use strict';
@@ -12,7 +12,7 @@ var VirtualListHelper = require('@danielgindi/virtual-list-helper');
12
12
  var keycodeJs = require('keycode-js');
13
13
  var mitt = require('mitt');
14
14
 
15
- var escapeRegex = ((value) => value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'));
15
+ var escapeRegex = (value) => value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
16
16
 
17
17
  const ItemSymbol$1 = Symbol('item');
18
18
  const DestroyedSymbol$1 = Symbol('destroyed');
@@ -138,7 +138,7 @@ class DropList {
138
138
  constructor(options) {
139
139
  const o = { ...defaultOptions$1 };
140
140
 
141
- for (let [key, value] of Object.entries( /**@type Object*/options))
141
+ for (let [key, value] of Object.entries(/**@type Object*/options))
142
142
  if (value !== undefined)
143
143
  o[key] = value;
144
144
 
@@ -192,7 +192,7 @@ class DropList {
192
192
  p.elOriginalDisplay = el.style.display || '';
193
193
  el.classList.add(...classes);
194
194
  el.role = 'menu';
195
- Css.setCssProps( /**@type ElementCSSInlineStyle*/el, initialCss);
195
+ Css.setCssProps(/**@type ElementCSSInlineStyle*/el, initialCss);
196
196
  p.ownsEl = false;
197
197
  } else {
198
198
  el = Dom.createElement('ul', {
@@ -226,7 +226,7 @@ class DropList {
226
226
  onItemRender: (itemEl, index) => {
227
227
  let item;
228
228
 
229
- if (( /**@type any*/index) === GhostSymbol) {
229
+ if ((/**@type any*/index) === GhostSymbol) {
230
230
  item = {
231
231
  label: p.lastMeasureLongestLabelText,
232
232
  value: 'Measure',
@@ -1596,7 +1596,7 @@ class DropList {
1596
1596
  * @param {function(any)} handler
1597
1597
  * @returns {DropList}
1598
1598
  */
1599
- on( /**string|'*'*/event, /**Function?*/handler) {
1599
+ on(/**string|'*'*/event, /**Function?*/handler) {
1600
1600
  this._p.mitt.on(event, handler);
1601
1601
  return this;
1602
1602
  }
@@ -1607,7 +1607,7 @@ class DropList {
1607
1607
  * @param {function(any)} handler
1608
1608
  * @returns {DropList}
1609
1609
  */
1610
- once( /**string|'*'*/event, /**Function?*/handler) {
1610
+ once(/**string|'*'*/event, /**Function?*/handler) {
1611
1611
  let wrapped = (value) => {
1612
1612
  this._p.mitt.off(event, wrapped);
1613
1613
  handler(value);
@@ -1622,7 +1622,7 @@ class DropList {
1622
1622
  * @param {function(any)} handler
1623
1623
  * @returns {DropList}
1624
1624
  */
1625
- off( /**(string|'*')?*/event, /**Function?*/handler) {
1625
+ off(/**(string|'*')?*/event, /**Function?*/handler) {
1626
1626
  if (!event && !event) {
1627
1627
  this._p.mitt.all.clear();
1628
1628
  } else {
@@ -1637,7 +1637,7 @@ class DropList {
1637
1637
  * @param {any} value
1638
1638
  * @returns {DropList}
1639
1639
  */
1640
- emit( /**string|'*'*/event, /**any?*/value) {
1640
+ emit(/**string|'*'*/event, /**any?*/value) {
1641
1641
  this._p.mitt.emit(event, value);
1642
1642
  return this;
1643
1643
  }
@@ -2663,7 +2663,7 @@ class SelectBox {
2663
2663
  constructor(options) {
2664
2664
  const o = { ...defaultOptions };
2665
2665
 
2666
- for (let [key, value] of Object.entries( /**@type Object*/options))
2666
+ for (let [key, value] of Object.entries(/**@type Object*/options))
2667
2667
  if (value !== undefined)
2668
2668
  o[key] = value;
2669
2669
 
@@ -2792,7 +2792,7 @@ class SelectBox {
2792
2792
  }, true);
2793
2793
 
2794
2794
  p.sink.
2795
- add(p.input, 'keydown', ( /**KeyboardEvent*/event) => {
2795
+ add(p.input, 'keydown', (/**KeyboardEvent*/event) => {
2796
2796
  this._handleInputKeydown(event);
2797
2797
  }).
2798
2798
  add(p.input, 'input', () => {
@@ -3431,7 +3431,7 @@ class SelectBox {
3431
3431
  p.selectedValues &&
3432
3432
  p.selectedValues.length === 1 &&
3433
3433
  Array.isArray(p.selectedValues[0])) {
3434
- this.setSelectedValues( /**@type Array*/p.selectedValues[0]);
3434
+ this.setSelectedValues(/**@type Array*/p.selectedValues[0]);
3435
3435
  }
3436
3436
 
3437
3437
  this._scheduleSync('full');
@@ -3976,7 +3976,7 @@ class SelectBox {
3976
3976
  * @param {function(any)} handler
3977
3977
  * @returns {SelectBox}
3978
3978
  */
3979
- on( /**string|'*'*/event, /**Function?*/handler) {
3979
+ on(/**string|'*'*/event, /**Function?*/handler) {
3980
3980
  this._p.mitt.on(event, handler);
3981
3981
  return this;
3982
3982
  }
@@ -3987,7 +3987,7 @@ class SelectBox {
3987
3987
  * @param {function(any)} handler
3988
3988
  * @returns {SelectBox}
3989
3989
  */
3990
- once( /**string|'*'*/event, /**Function?*/handler) {
3990
+ once(/**string|'*'*/event, /**Function?*/handler) {
3991
3991
  let wrapped = (value) => {
3992
3992
  this._p.mitt.off(event, wrapped);
3993
3993
  handler(value);
@@ -4002,7 +4002,7 @@ class SelectBox {
4002
4002
  * @param {function(any)} handler
4003
4003
  * @returns {SelectBox}
4004
4004
  */
4005
- off( /**(string|'*')?*/event, /**Function?*/handler) {
4005
+ off(/**(string|'*')?*/event, /**Function?*/handler) {
4006
4006
  if (!event && !event) {
4007
4007
  this._p.mitt.all.clear();
4008
4008
  } else {
@@ -4017,7 +4017,7 @@ class SelectBox {
4017
4017
  * @param {any} value
4018
4018
  * @returns {SelectBox}
4019
4019
  */
4020
- emit( /**string|'*'*/event, /**any?*/value) {
4020
+ emit(/**string|'*'*/event, /**any?*/value) {
4021
4021
  this._p.mitt.emit(event, value);
4022
4022
  return this;
4023
4023
  }
@@ -4108,7 +4108,7 @@ class SelectBox {
4108
4108
  Dom.closestUntil(evt.target, `.${p.baseClassName}__item`, evt.currentTarget),
4109
4109
  evt);
4110
4110
  }).
4111
- add(p.list, 'keydown', ( /**KeyboardEvent*/evt) => {
4111
+ add(p.list, 'keydown', (/**KeyboardEvent*/evt) => {
4112
4112
  if (!Dom.closestUntil(evt.target, `.${p.baseClassName}__item`, evt.currentTarget))
4113
4113
  return;
4114
4114
 
@@ -4396,6 +4396,8 @@ class SelectBox {
4396
4396
  if (!hasGroupSync)
4397
4397
  this._scheduleSync('render_base');
4398
4398
  }
4399
+ } else if (p.multi) {
4400
+ this._scheduleSync('_syncPlaceholder');
4399
4401
  }
4400
4402
 
4401
4403
  this._trigger(checked ? 'addsel' : 'removesel', { value: value, item: item });
@@ -4490,7 +4492,7 @@ class SelectBox {
4490
4492
 
4491
4493
  p.sink.
4492
4494
  add(keyEventsTarget, 'keydown.dropdown', (evt) => {
4493
- if (( /**@type HTMLInputElement*/evt.currentTarget).readOnly)
4495
+ if ((/**@type HTMLInputElement*/evt.currentTarget).readOnly)
4494
4496
  return;
4495
4497
 
4496
4498
  let suppressEnterSpaceToggle = false;
@@ -4978,6 +4980,10 @@ class SelectBox {
4978
4980
  this._syncSingleItem();
4979
4981
  break;
4980
4982
 
4983
+ case 'syncPlaceholder':
4984
+ this._syncPlaceholder();
4985
+ break;
4986
+
4981
4987
  case 'removeMultiItemElement':{
4982
4988
  if (p.showSelection) {
4983
4989
  this._syncPlaceholder();
@@ -5201,7 +5207,9 @@ class SelectBox {
5201
5207
  if (typeof p.multiPlaceholderFormatter === 'function') {
5202
5208
  placeholder = p.multiPlaceholderFormatter(p.selectedItems);
5203
5209
  } else {
5204
- placeholder = defaultMultiPlaceholderFormatter(p.selectedItems, p.labelProp);
5210
+ placeholder = p.selectedItems.length === 0 ?
5211
+ p.placeholder || '' :
5212
+ defaultMultiPlaceholderFormatter(p.selectedItems, p.labelProp);
5205
5213
  }
5206
5214
  } else if (p.selectedItems.length === 0 ||
5207
5215
  !p.showSelection ||
@@ -5709,7 +5717,7 @@ class SelectBox {
5709
5717
  let nextFocus;
5710
5718
 
5711
5719
  if (event.key === (isRtl ? keycodeJs.VALUE_LEFT : keycodeJs.VALUE_RIGHT)) {// Next arrow
5712
- nextFocus = Dom.next( /**@type Element*/event.target, `.${p.baseClassName}__item,.${p.baseClassName}__search_wrapper`);
5720
+ nextFocus = Dom.next(/**@type Element*/event.target, `.${p.baseClassName}__item,.${p.baseClassName}__search_wrapper`);
5713
5721
  if (hasClass(nextFocus, `${p.baseClassName}__search_wrapper`)) {
5714
5722
  nextFocus = nextFocus.querySelector('input');
5715
5723
  }
@@ -5717,7 +5725,7 @@ class SelectBox {
5717
5725
 
5718
5726
  event.preventDefault();
5719
5727
  } else if (event.key === (isRtl ? keycodeJs.VALUE_RIGHT : keycodeJs.VALUE_LEFT)) {// Prev arrow
5720
- nextFocus = Dom.prev( /**@type Element*/event.target, `.${p.baseClassName}__item,.${p.baseClassName}__search_wrapper`);
5728
+ nextFocus = Dom.prev(/**@type Element*/event.target, `.${p.baseClassName}__item,.${p.baseClassName}__search_wrapper`);
5721
5729
  if (hasClass(nextFocus, `${p.baseClassName}__search_wrapper`)) {
5722
5730
  nextFocus = nextFocus.querySelector('input');
5723
5731
  }
@@ -5729,7 +5737,7 @@ class SelectBox {
5729
5737
  let itemEl = event.target;
5730
5738
  while (itemEl) {
5731
5739
  multiItemEls.push(itemEl);
5732
- itemEl = Dom.prev( /**@type Element*/itemEl, `.${p.baseClassName}__item`);
5740
+ itemEl = Dom.prev(/**@type Element*/itemEl, `.${p.baseClassName}__item`);
5733
5741
  }
5734
5742
 
5735
5743
  while (multiItemEls.length) {