gd-bs 6.7.6 → 6.7.7

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.
@@ -81,6 +81,8 @@ var DropdownFormItem = /** @class */ (function () {
81
81
  enumerable: false,
82
82
  configurable: true
83
83
  });
84
+ // Hides the item
85
+ DropdownFormItem.prototype.hide = function () { this._el.classList.add("d-none"); };
84
86
  Object.defineProperty(DropdownFormItem.prototype, "isSelected", {
85
87
  // Returns true if the item is selected
86
88
  get: function () { return this._isSelected; },
@@ -94,6 +96,8 @@ var DropdownFormItem = /** @class */ (function () {
94
96
  enumerable: false,
95
97
  configurable: true
96
98
  });
99
+ // Shows the item
100
+ DropdownFormItem.prototype.show = function () { this._el.classList.remove("d-none"); };
97
101
  // Toggles the item selection
98
102
  DropdownFormItem.prototype.toggle = function () {
99
103
  // Skip the dividers, headers
@@ -78,6 +78,8 @@ var _Dropdown = /** @class */ (function (_super) {
78
78
  _this.configure();
79
79
  // Configure the events
80
80
  _this.configureEvents();
81
+ // Configure search
82
+ _this.configureSearch();
81
83
  // Configure the parent
82
84
  _this.configureParent();
83
85
  // Set the flag
@@ -273,6 +275,17 @@ var _Dropdown = /** @class */ (function (_super) {
273
275
  elTarget: toggle,
274
276
  placement: typeof (this.props.placement) === "number" ? this.props.placement : floating_ui_1.FloatingUIPlacements.BottomStart,
275
277
  theme: popoverType,
278
+ onShow: function () {
279
+ // See if the search element exists
280
+ if (_this._elSearch) {
281
+ // Clear the search
282
+ _this._elSearch.value = "";
283
+ // Show all the items
284
+ for (var i = 0; i < _this._items.length; i++) {
285
+ _this._items[i].show();
286
+ }
287
+ }
288
+ },
276
289
  options: {
277
290
  arrow: false,
278
291
  flip: true,
@@ -402,6 +415,66 @@ var _Dropdown = /** @class */ (function (_super) {
402
415
  }
403
416
  }
404
417
  };
418
+ // Configures the search option for the dropdown
419
+ _Dropdown.prototype.configureSearch = function () {
420
+ var _this = this;
421
+ // See if search is enabled and the menu exists
422
+ if (this.props.search != true || this._elMenu == null) {
423
+ return;
424
+ }
425
+ // Create the search textbox
426
+ this._elSearch = document.createElement("input");
427
+ this._elSearch.classList.add("form-control");
428
+ this._elSearch.type = "search";
429
+ this._elSearch.placeholder = "Search for item...";
430
+ // Insert the item as the first element
431
+ this._elMenu.firstChild ? this._elMenu.insertBefore(this._elSearch, this._elMenu.firstChild) : this._elMenu.appendChild(this._elSearch);
432
+ // Create the empty text
433
+ var elEmptyText = document.createElement("h6");
434
+ elEmptyText.classList.add("dropdown-header");
435
+ elEmptyText.classList.add("d-none");
436
+ elEmptyText.innerHTML = "No items were found...";
437
+ this._elMenu.appendChild(elEmptyText);
438
+ // Add the element to the ignore list
439
+ this._floatingUI.addIgnoreElement(this._elSearch);
440
+ // Add the event
441
+ this._elSearch.addEventListener("input", function () {
442
+ // Get the value
443
+ var searchText = (_this._elSearch.value || "").toLocaleLowerCase();
444
+ // Set the flags
445
+ var itemsFound = false;
446
+ var showAll = searchText == "";
447
+ // Hide the empty text
448
+ elEmptyText.classList.add("d-none");
449
+ // Parse the items
450
+ for (var i = 0; i < _this._items.length; i++) {
451
+ var item = _this._items[i];
452
+ // See if we are showing all the items
453
+ if (showAll) {
454
+ // Show the item
455
+ item.show();
456
+ }
457
+ else {
458
+ // See if the value contains the text
459
+ if ((item.props.text || "").toLowerCase().indexOf(searchText) >= 0) {
460
+ // Show the item
461
+ item.show();
462
+ // Set the flag
463
+ itemsFound = true;
464
+ }
465
+ else {
466
+ // Hide the item
467
+ item.hide();
468
+ }
469
+ }
470
+ }
471
+ // See if no items were found
472
+ if (!showAll && !itemsFound) {
473
+ // Show the empty message
474
+ elEmptyText.classList.remove("d-none");
475
+ }
476
+ });
477
+ };
405
478
  // Generates the checkbox items
406
479
  _Dropdown.prototype.generateCheckboxItems = function () {
407
480
  var cbItems = [];
@@ -633,6 +706,8 @@ var _Dropdown = /** @class */ (function (_super) {
633
706
  }
634
707
  }
635
708
  }
709
+ // Configure search
710
+ this.configureSearch();
636
711
  };
637
712
  // Sets the label of the dropdown
638
713
  _Dropdown.prototype.setLabel = function (value) {
@@ -142,6 +142,8 @@ var DropdownItem = /** @class */ (function () {
142
142
  enumerable: false,
143
143
  configurable: true
144
144
  });
145
+ // Hides the item
146
+ DropdownItem.prototype.hide = function () { this._el.classList.add("d-none"); };
145
147
  Object.defineProperty(DropdownItem.prototype, "isSelected", {
146
148
  // Returns true if the item is selected
147
149
  get: function () { return this._isSelected; },
@@ -154,6 +156,8 @@ var DropdownItem = /** @class */ (function () {
154
156
  enumerable: false,
155
157
  configurable: true
156
158
  });
159
+ // Shows the item
160
+ DropdownItem.prototype.show = function () { this._el.classList.remove("d-none"); };
157
161
  // Toggles the item selection
158
162
  DropdownItem.prototype.toggle = function () {
159
163
  // Skip the dividers, headers and nav items
@@ -50,10 +50,12 @@ var _FloatingUI = /** @class */ (function () {
50
50
  function _FloatingUI(props) {
51
51
  var _a;
52
52
  this._elArrow = null;
53
- this._elTarget = null;
54
53
  this._elContent = null;
54
+ this._elIgnore = null;
55
+ this._elTarget = null;
55
56
  this._options = null;
56
57
  this._props = null;
58
+ this._elIgnore = [];
57
59
  this._elTarget = props.elTarget;
58
60
  this._props = props;
59
61
  // Create the content element
@@ -70,6 +72,7 @@ var _FloatingUI = /** @class */ (function () {
70
72
  // Set the visibility
71
73
  this._props.show ? this.show() : this.hide();
72
74
  }
75
+ // Add the events to trigger, refresh and hide the element
73
76
  _FloatingUI.prototype.addEvents = function (trigger) {
74
77
  var _this = this;
75
78
  if (trigger === void 0) { trigger = ""; }
@@ -88,45 +91,30 @@ var _FloatingUI = /** @class */ (function () {
88
91
  _this.isVisible ? _this.hide() : _this.show();
89
92
  });
90
93
  }
91
- // Add the events
92
- _FloatingUI.Events.push(function (ev) {
93
- // See if it's outside the target element
94
- if (!_this._elTarget.contains(ev.target)) {
95
- // Hide the element
96
- _this.hide();
94
+ // Create the event
95
+ document.addEventListener("click", function (ev) {
96
+ // Do nothing if we toggled this component
97
+ if (_this._elTarget.contains(ev.target)) {
98
+ return;
97
99
  }
100
+ // Parse the elements to ignore
101
+ for (var i = 0; i < _this._elIgnore.length; i++) {
102
+ // Do nothing if it triggered the click
103
+ if (_this._elIgnore[i].contains(ev.target)) {
104
+ return;
105
+ }
106
+ }
107
+ // Hide the element
108
+ _this.hide();
98
109
  });
99
- _FloatingUI.ScrollEvents.push(function (ev) {
100
- // Refresh the content
101
- _this.refresh();
110
+ // Create the scroll event
111
+ window.addEventListener("scroll", function (ev) {
112
+ // Wait for the other events to run
113
+ setTimeout(function () {
114
+ // Refresh the content
115
+ _this.refresh();
116
+ }, 10);
102
117
  });
103
- // Ensure the click event exists
104
- if (!_FloatingUI.EventsCreated) {
105
- // Create the event
106
- document.addEventListener("click", function (ev) {
107
- // Wait for the other events to run
108
- setTimeout(function () {
109
- // Parse the events
110
- _FloatingUI.Events.forEach(function (fnEvent) {
111
- // Call the event
112
- fnEvent(ev);
113
- });
114
- }, 10);
115
- });
116
- // Create the scroll event
117
- window.addEventListener("scroll", function (ev) {
118
- // Wait for the other events to run
119
- setTimeout(function () {
120
- // Parse the events
121
- _FloatingUI.ScrollEvents.forEach(function (fnEvent) {
122
- // Call the event
123
- fnEvent(ev);
124
- });
125
- }, 10);
126
- });
127
- // Set the flag
128
- _FloatingUI.EventsCreated = true;
129
- }
130
118
  };
131
119
  // Creates the floating ui
132
120
  _FloatingUI.prototype.create = function () {
@@ -339,13 +327,28 @@ var _FloatingUI = /** @class */ (function () {
339
327
  /**
340
328
  * Public Methods
341
329
  */
330
+ _FloatingUI.prototype.addIgnoreElement = function (el) { this._elIgnore.push(el); };
331
+ _FloatingUI.prototype.removeIgnoreElement = function (el) {
332
+ // Parse the elements
333
+ for (var i = 0; i < this._elIgnore.length; i++) {
334
+ // See if this is the element to remove
335
+ if (this._elIgnore[i].isEqualNode(el)) {
336
+ // Remove it
337
+ this._elIgnore.splice(i, 1);
338
+ return;
339
+ }
340
+ }
341
+ };
342
342
  _FloatingUI.prototype.setContent = function (el) { this._elContent = el; this.refresh(); };
343
343
  // Hides the content
344
344
  _FloatingUI.prototype.hide = function () {
345
345
  // Remove it from the document
346
346
  this._elContent.classList.add("d-none");
347
347
  if (document.body.contains(this._elContent)) {
348
+ // Remove the element from the page
348
349
  document.body.removeChild(this._elContent);
350
+ // Call the event
351
+ this._props.onHide ? this._props.onHide() : null;
349
352
  }
350
353
  };
351
354
  Object.defineProperty(_FloatingUI.prototype, "isVisible", {
@@ -359,16 +362,16 @@ var _FloatingUI = /** @class */ (function () {
359
362
  // Append it to the document
360
363
  this._elContent.classList.remove("d-none");
361
364
  if (!document.body.contains(this._elContent)) {
365
+ // Add the element to the page
362
366
  document.body.appendChild(this._elContent);
367
+ // Refresh the position
363
368
  this.refresh();
369
+ // Call the event
370
+ this._props.onShow ? this._props.onShow() : null;
364
371
  }
365
372
  };
366
373
  // Toggles the floating ui
367
374
  _FloatingUI.prototype.toggle = function () { this.isVisible ? this.hide() : this.show(); };
368
- // Static events
369
- _FloatingUI.Events = [];
370
- _FloatingUI.EventsCreated = false;
371
- _FloatingUI.ScrollEvents = [];
372
375
  return _FloatingUI;
373
376
  }());
374
377
  var FloatingUI = function (props) { return new _FloatingUI(props); };