gd-bs 6.7.6 → 6.7.8

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 () {
@@ -318,12 +306,15 @@ var _FloatingUI = /** @class */ (function () {
318
306
  if (_this._elArrow) {
319
307
  var arrowX = middlewareData.arrow.x;
320
308
  var arrowY = middlewareData.arrow.y;
309
+ var placement = (((_c = middlewareData.offset) === null || _c === void 0 ? void 0 : _c.placement) || _this._options.placement).split('-')[0];
321
310
  var side = {
322
311
  top: 'bottom',
323
312
  right: 'left',
324
313
  bottom: 'top',
325
314
  left: 'right'
326
- }[(((_c = middlewareData.offset) === null || _c === void 0 ? void 0 : _c.placement) || _this._options.placement).split('-')[0]];
315
+ }[placement];
316
+ // Set the placement
317
+ _this._elContent.setAttribute("data-placement", placement);
327
318
  // Update the location
328
319
  Object.assign(_this._elArrow.style, (_b = {
329
320
  left: arrowX != null ? "".concat(arrowX, "px") : '',
@@ -339,13 +330,28 @@ var _FloatingUI = /** @class */ (function () {
339
330
  /**
340
331
  * Public Methods
341
332
  */
333
+ _FloatingUI.prototype.addIgnoreElement = function (el) { this._elIgnore.push(el); };
334
+ _FloatingUI.prototype.removeIgnoreElement = function (el) {
335
+ // Parse the elements
336
+ for (var i = 0; i < this._elIgnore.length; i++) {
337
+ // See if this is the element to remove
338
+ if (this._elIgnore[i].isEqualNode(el)) {
339
+ // Remove it
340
+ this._elIgnore.splice(i, 1);
341
+ return;
342
+ }
343
+ }
344
+ };
342
345
  _FloatingUI.prototype.setContent = function (el) { this._elContent = el; this.refresh(); };
343
346
  // Hides the content
344
347
  _FloatingUI.prototype.hide = function () {
345
348
  // Remove it from the document
346
349
  this._elContent.classList.add("d-none");
347
350
  if (document.body.contains(this._elContent)) {
351
+ // Remove the element from the page
348
352
  document.body.removeChild(this._elContent);
353
+ // Call the event
354
+ this._props.onHide ? this._props.onHide() : null;
349
355
  }
350
356
  };
351
357
  Object.defineProperty(_FloatingUI.prototype, "isVisible", {
@@ -359,16 +365,16 @@ var _FloatingUI = /** @class */ (function () {
359
365
  // Append it to the document
360
366
  this._elContent.classList.remove("d-none");
361
367
  if (!document.body.contains(this._elContent)) {
368
+ // Add the element to the page
362
369
  document.body.appendChild(this._elContent);
370
+ // Refresh the position
363
371
  this.refresh();
372
+ // Call the event
373
+ this._props.onShow ? this._props.onShow() : null;
364
374
  }
365
375
  };
366
376
  // Toggles the floating ui
367
377
  _FloatingUI.prototype.toggle = function () { this.isVisible ? this.hide() : this.show(); };
368
- // Static events
369
- _FloatingUI.Events = [];
370
- _FloatingUI.EventsCreated = false;
371
- _FloatingUI.ScrollEvents = [];
372
378
  return _FloatingUI;
373
379
  }());
374
380
  var FloatingUI = function (props) { return new _FloatingUI(props); };