@keenthemes/ktui 1.0.23 → 1.0.25

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/ktui.js CHANGED
@@ -2636,7 +2636,6 @@ var component_1 = __webpack_require__(2658);
2636
2636
  var KTImageInput = /** @class */ (function (_super) {
2637
2637
  __extends(KTImageInput, _super);
2638
2638
  function KTImageInput(element, config) {
2639
- if (config === void 0) { config = null; }
2640
2639
  var _this = _super.call(this) || this;
2641
2640
  _this._name = 'image-input';
2642
2641
  _this._defaultConfig = {
@@ -2683,8 +2682,6 @@ var KTImageInput = /** @class */ (function (_super) {
2683
2682
  };
2684
2683
  reader.readAsDataURL(this._inputElement.files[0]);
2685
2684
  this._selectedFile = this._inputElement.files[0];
2686
- this._inputElement.value = '';
2687
- this._hiddenElement.value = '';
2688
2685
  this._lastMode = 'new';
2689
2686
  this._element.classList.add('changed');
2690
2687
  this._removeElement.classList.remove('hidden');
@@ -11630,6 +11627,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
11630
11627
  Object.defineProperty(exports, "__esModule", ({ value: true }));
11631
11628
  exports.KTSelect = void 0;
11632
11629
  var data_1 = __webpack_require__(8716);
11630
+ var dom_1 = __webpack_require__(9010);
11633
11631
  var component_1 = __webpack_require__(2658);
11634
11632
  var config_1 = __webpack_require__(9386);
11635
11633
  var option_1 = __webpack_require__(4241);
@@ -11662,6 +11660,7 @@ var KTSelect = /** @class */ (function (_super) {
11662
11660
  _this._selectAllButtonToggle = null;
11663
11661
  _this._typeToSearchBuffer = new utils_1.TypeToSearchBuffer();
11664
11662
  _this._mutationObserver = null;
11663
+ _this._preSelectedValues = [];
11665
11664
  // Search debounce timeout
11666
11665
  _this._searchDebounceTimeout = null;
11667
11666
  // Store original options HTML for restoring after search
@@ -11696,6 +11695,31 @@ var KTSelect = /** @class */ (function (_super) {
11696
11695
  }
11697
11696
  return _this;
11698
11697
  }
11698
+ /**
11699
+ * Set global select configuration options.
11700
+ * This allows setting default configuration that will be applied to all new KTSelect instances.
11701
+ * @param options Partial select config to merge with global config.
11702
+ * @example
11703
+ * KTSelect.config({
11704
+ * enableSearch: true,
11705
+ * searchPlaceholder: 'Type to search...',
11706
+ * dropdownZindex: 9999,
11707
+ * height: 300
11708
+ * });
11709
+ */
11710
+ KTSelect.config = function (options) {
11711
+ this.globalConfig = __assign(__assign({}, this.globalConfig), options);
11712
+ };
11713
+ /**
11714
+ * Override _buildConfig to include static globalConfig in the merge chain
11715
+ */
11716
+ KTSelect.prototype._buildConfig = function (config) {
11717
+ if (config === void 0) { config = {}; }
11718
+ if (!this._element)
11719
+ return;
11720
+ // Cast to writable to allow assignment (config is readonly but needs initialization)
11721
+ this._config = __assign(__assign(__assign(__assign(__assign({}, this._defaultConfig), KTSelect.globalConfig), this._getGlobalConfig()), dom_1.default.getDataAttributes(this._element, this._dataOptionPrefix + this._name)), config);
11722
+ };
11699
11723
  /**
11700
11724
  * Initialize remote data fetching
11701
11725
  */
@@ -11750,6 +11774,14 @@ var KTSelect = /** @class */ (function (_super) {
11750
11774
  * Clear existing options from the select element
11751
11775
  */
11752
11776
  KTSelect.prototype._clearExistingOptions = function () {
11777
+ // Capture pre-selected values before clearing (for remote data)
11778
+ var selectedOptions = Array.from(this._element.querySelectorAll('option[selected]:not([value=""])'));
11779
+ if (selectedOptions.length > 0) {
11780
+ this._preSelectedValues = selectedOptions.map(function (opt) { return opt.value; });
11781
+ if (this._config.debug) {
11782
+ console.log('Captured pre-selected values before clearing:', this._preSelectedValues);
11783
+ }
11784
+ }
11753
11785
  // Keep only the empty/placeholder option and remove the rest
11754
11786
  var options = Array.from(this._element.querySelectorAll('option:not([value=""])'));
11755
11787
  options.forEach(function (option) { return option.remove(); });
@@ -11806,7 +11838,7 @@ var KTSelect = /** @class */ (function (_super) {
11806
11838
  // Batch append all options at once
11807
11839
  optionsContainer.appendChild(fragment);
11808
11840
  // Update options NodeList
11809
- this._options = this._wrapperElement.querySelectorAll('[data-kt-select-option]');
11841
+ this._options = this._dropdownContentElement.querySelectorAll('[data-kt-select-option]');
11810
11842
  if (this._config.debug) {
11811
11843
  console.log("Rendered ".concat(optionsData.length, " options in dropdown"));
11812
11844
  }
@@ -11826,6 +11858,47 @@ var KTSelect = /** @class */ (function (_super) {
11826
11858
  KTSelect.prototype._completeRemoteSetup = function () {
11827
11859
  // Initialize options
11828
11860
  this._preSelectOptions(this._element);
11861
+ // Apply pre-selected values captured before remote data was loaded
11862
+ if (this._preSelectedValues.length > 0) {
11863
+ if (this._config.debug) {
11864
+ console.log('Applying pre-selected values after remote data loaded:', this._preSelectedValues);
11865
+ }
11866
+ // Get all available option values from the loaded remote data
11867
+ var availableValues_1 = Array.from(this._element.querySelectorAll('option')).map(function (opt) { return opt.value; });
11868
+ // Filter pre-selected values to only those that exist in remote data
11869
+ var validPreSelectedValues = this._preSelectedValues.filter(function (value) {
11870
+ return availableValues_1.includes(value);
11871
+ });
11872
+ if (validPreSelectedValues.length > 0) {
11873
+ // For single-select mode, only use the first value
11874
+ var valuesToSelect = this._config.multiple
11875
+ ? validPreSelectedValues
11876
+ : [validPreSelectedValues[0]];
11877
+ if (this._config.debug) {
11878
+ console.log('Selecting matched values:', valuesToSelect);
11879
+ }
11880
+ // Get any existing selections from _preSelectOptions (e.g., data-kt-select-pre-selected)
11881
+ var existingSelections = this._state.getSelectedOptions();
11882
+ // Merge existing selections with native pre-selected values (no duplicates)
11883
+ var allSelections_1 = this._config.multiple
11884
+ ? Array.from(new Set(__spreadArray(__spreadArray([], existingSelections, true), valuesToSelect, true)))
11885
+ : valuesToSelect;
11886
+ // Set all selections at once to avoid toggling issues
11887
+ this._state.setSelectedOptions(allSelections_1);
11888
+ // Update the native select element to match
11889
+ Array.from(this._element.querySelectorAll('option')).forEach(function (opt) {
11890
+ opt.selected = allSelections_1.includes(opt.value);
11891
+ });
11892
+ // Update the visual display
11893
+ this.updateSelectedOptionDisplay();
11894
+ this._updateSelectedOptionClass();
11895
+ }
11896
+ else if (this._config.debug) {
11897
+ console.log('None of the pre-selected values matched remote data:', this._preSelectedValues);
11898
+ }
11899
+ // Clear the pre-selected values array after processing
11900
+ this._preSelectedValues = [];
11901
+ }
11829
11902
  // Apply disabled state if needed
11830
11903
  this._applyInitialDisabledState();
11831
11904
  // Initialize search if enabled
@@ -12009,7 +12082,7 @@ var KTSelect = /** @class */ (function (_super) {
12009
12082
  }
12010
12083
  });
12011
12084
  // Update options NodeList to include the new options
12012
- this._options = this._wrapperElement.querySelectorAll("[data-kt-select-option]");
12085
+ this._options = this._dropdownContentElement.querySelectorAll("[data-kt-select-option]");
12013
12086
  if (this._config.debug)
12014
12087
  console.log("Added ".concat(newItems.length, " more options to dropdown"));
12015
12088
  };
@@ -12153,7 +12226,7 @@ var KTSelect = /** @class */ (function (_super) {
12153
12226
  this._selectAllButton = this._wrapperElement.querySelector('[data-kt-select-select-all]');
12154
12227
  // Cache the options container for performance
12155
12228
  this._optionsContainer = this._dropdownContentElement.querySelector('[data-kt-select-options]');
12156
- this._options = this._wrapperElement.querySelectorAll("[data-kt-select-option]");
12229
+ this._options = this._dropdownContentElement.querySelectorAll("[data-kt-select-option]");
12157
12230
  };
12158
12231
  /**
12159
12232
  * Attach all event listeners to elements
@@ -12523,7 +12596,7 @@ var KTSelect = /** @class */ (function (_super) {
12523
12596
  */
12524
12597
  KTSelect.prototype._updateSelectedOptionClass = function () {
12525
12598
  var _this = this;
12526
- var allOptions = this._wrapperElement.querySelectorAll("[data-kt-select-option]");
12599
+ var allOptions = this._dropdownContentElement.querySelectorAll("[data-kt-select-option]");
12527
12600
  var selectedValues = this._state.getSelectedOptions();
12528
12601
  var maxReached = typeof this._config.maxSelections === 'number' &&
12529
12602
  selectedValues.length >= this._config.maxSelections;
@@ -12736,7 +12809,7 @@ var KTSelect = /** @class */ (function (_super) {
12736
12809
  */
12737
12810
  KTSelect.prototype.showAllOptions = function () {
12738
12811
  // Get all options in the dropdown
12739
- var options = Array.from(this._wrapperElement.querySelectorAll("[data-kt-select-option]"));
12812
+ var options = Array.from(this._dropdownContentElement.querySelectorAll("[data-kt-select-option]"));
12740
12813
  // Show all options by removing the hidden class and any inline styles
12741
12814
  options.forEach(function (option) {
12742
12815
  var _a;
@@ -12883,17 +12956,109 @@ var KTSelect = /** @class */ (function (_super) {
12883
12956
  // Call parent dispose to clean up data
12884
12957
  _super.prototype.dispose.call(this);
12885
12958
  };
12959
+ /**
12960
+ * ========================================================================
12961
+ * DYNAMIC CONTROL METHODS
12962
+ * ========================================================================
12963
+ */
12964
+ /**
12965
+ * Programmatically enable the select component
12966
+ * @public
12967
+ */
12968
+ KTSelect.prototype.enable = function () {
12969
+ // Update config state
12970
+ this._config.disabled = false;
12971
+ // Remove disabled attribute from native select
12972
+ this._element.removeAttribute('disabled');
12973
+ this._element.classList.remove('disabled');
12974
+ // Remove disabled state from wrapper and display elements
12975
+ if (this._wrapperElement) {
12976
+ this._wrapperElement.classList.remove('disabled');
12977
+ }
12978
+ if (this._displayElement) {
12979
+ this._displayElement.removeAttribute('aria-disabled');
12980
+ }
12981
+ // Dispatch enabled event
12982
+ this._dispatchEvent('enabled');
12983
+ this._fireEvent('enabled');
12984
+ };
12985
+ /**
12986
+ * Programmatically disable the select component
12987
+ * @public
12988
+ */
12989
+ KTSelect.prototype.disable = function () {
12990
+ // Update config state
12991
+ this._config.disabled = true;
12992
+ // Close dropdown if currently open
12993
+ if (this._dropdownIsOpen) {
12994
+ this.closeDropdown();
12995
+ }
12996
+ // Add disabled attribute to native select
12997
+ this._element.setAttribute('disabled', 'disabled');
12998
+ this._element.classList.add('disabled');
12999
+ // Add disabled state to wrapper and display elements
13000
+ if (this._wrapperElement) {
13001
+ this._wrapperElement.classList.add('disabled');
13002
+ }
13003
+ if (this._displayElement) {
13004
+ this._displayElement.setAttribute('aria-disabled', 'true');
13005
+ }
13006
+ // Dispatch disabled event
13007
+ this._dispatchEvent('disabled');
13008
+ this._fireEvent('disabled');
13009
+ };
13010
+ /**
13011
+ * Update the dropdown to sync with native select element changes
13012
+ * Optionally accepts new options to replace existing ones
13013
+ * @param newOptions Optional array of new options [{value, text}, ...]
13014
+ * @public
13015
+ */
13016
+ KTSelect.prototype.update = function (newOptions) {
13017
+ var _this = this;
13018
+ if (newOptions) {
13019
+ // Clear existing options except placeholder
13020
+ this._clearExistingOptions();
13021
+ // Add new options to native select
13022
+ newOptions.forEach(function (opt) {
13023
+ var option = document.createElement('option');
13024
+ option.value = opt.value;
13025
+ option.textContent = opt.text;
13026
+ _this._element.appendChild(option);
13027
+ });
13028
+ }
13029
+ // Rebuild dropdown from native select
13030
+ this._rebuildOptionsFromNative();
13031
+ // Dispatch updated event
13032
+ this._dispatchEvent('updated');
13033
+ this._fireEvent('updated');
13034
+ };
13035
+ /**
13036
+ * Refresh the visual display and state without rebuilding options
13037
+ * @public
13038
+ */
13039
+ KTSelect.prototype.refresh = function () {
13040
+ // Sync internal state from native select first
13041
+ this._syncSelectionFromNative();
13042
+ // Reapply ARIA attributes
13043
+ this._setAriaAttributes();
13044
+ // Dispatch refreshed event
13045
+ this._dispatchEvent('refreshed');
13046
+ this._fireEvent('refreshed');
13047
+ };
13048
+ /**
13049
+ * ========================================================================
13050
+ * STATIC METHODS
13051
+ * ========================================================================
13052
+ */
12886
13053
  /**
12887
13054
  * Create instances of KTSelect for all matching elements
12888
13055
  */
12889
13056
  KTSelect.createInstances = function () {
12890
- var _this = this;
12891
13057
  var elements = document.querySelectorAll('[data-kt-select]');
12892
13058
  elements.forEach(function (element) {
12893
13059
  if (element.hasAttribute('data-kt-select') &&
12894
13060
  !element.classList.contains('data-kt-select-initialized')) {
12895
- var instance = new KTSelect(element);
12896
- _this._instances.set(element, instance);
13061
+ new KTSelect(element);
12897
13062
  }
12898
13063
  });
12899
13064
  };
@@ -12903,6 +13068,26 @@ var KTSelect = /** @class */ (function (_super) {
12903
13068
  KTSelect.init = function () {
12904
13069
  KTSelect.createInstances();
12905
13070
  };
13071
+ /**
13072
+ * Get an existing KTSelect instance from an element
13073
+ */
13074
+ KTSelect.getInstance = function (element) {
13075
+ if (!element)
13076
+ return null;
13077
+ if (data_1.default.has(element, 'select')) {
13078
+ return data_1.default.get(element, 'select');
13079
+ }
13080
+ if (element.getAttribute('data-kt-select')) {
13081
+ return new KTSelect(element);
13082
+ }
13083
+ return null;
13084
+ };
13085
+ /**
13086
+ * Get an existing KTSelect instance or create a new one
13087
+ */
13088
+ KTSelect.getOrCreateInstance = function (element, config) {
13089
+ return this.getInstance(element) || new KTSelect(element, config);
13090
+ };
12906
13091
  /**
12907
13092
  * Handle remote search
12908
13093
  * @param event Input event
@@ -12993,7 +13178,7 @@ var KTSelect = /** @class */ (function (_super) {
12993
13178
  // Restore original options
12994
13179
  optionsContainer.innerHTML = this._originalOptionsHtml;
12995
13180
  // Update options NodeList
12996
- this._options = this._wrapperElement.querySelectorAll('[data-kt-select-option]');
13181
+ this._options = this._dropdownContentElement.querySelectorAll('[data-kt-select-option]');
12997
13182
  // Refresh search module
12998
13183
  if (this._searchModule) {
12999
13184
  this._searchModule.refreshAfterSearch();
@@ -13022,13 +13207,40 @@ var KTSelect = /** @class */ (function (_super) {
13022
13207
  optionsContainer.appendChild(noResultsElement);
13023
13208
  return;
13024
13209
  }
13025
- // Use unified renderer for search results
13026
- this._renderOptionsInDropdown(items, true);
13210
+ // First update the original select element with search results
13211
+ this._updateOriginalSelectWithSearchResults(items);
13212
+ // Then update dropdown using the standard flow
13213
+ this._updateDropdownWithNewOptions();
13027
13214
  // Add pagination "Load More" button if needed
13028
13215
  if (this._config.pagination && this._remoteModule.hasMorePages()) {
13029
13216
  this._addLoadMoreButton();
13030
13217
  }
13031
13218
  };
13219
+ /**
13220
+ * Update original select element with search results
13221
+ * @param items Search result items
13222
+ */
13223
+ KTSelect.prototype._updateOriginalSelectWithSearchResults = function (items) {
13224
+ var _this = this;
13225
+ // Clear existing options except placeholder
13226
+ this._clearExistingOptions();
13227
+ // Add search result items to original select element
13228
+ items.forEach(function (item) {
13229
+ var optionElement = document.createElement('option');
13230
+ optionElement.value = item.id || '';
13231
+ optionElement.textContent = item.title || '';
13232
+ if (item.selected) {
13233
+ optionElement.setAttribute('selected', 'selected');
13234
+ }
13235
+ if (item.disabled) {
13236
+ optionElement.setAttribute('disabled', 'disabled');
13237
+ }
13238
+ _this._element.appendChild(optionElement);
13239
+ });
13240
+ if (this._config.debug) {
13241
+ console.log("Updated original select with ".concat(items.length, " search results"));
13242
+ }
13243
+ };
13032
13244
  /**
13033
13245
  * Check if dropdown is open
13034
13246
  */
@@ -13271,7 +13483,7 @@ var KTSelect = /** @class */ (function (_super) {
13271
13483
  optionsContainer_1.appendChild(renderedOption);
13272
13484
  });
13273
13485
  // Update internal references
13274
- this._options = this._wrapperElement.querySelectorAll('[data-kt-select-option]');
13486
+ this._options = this._dropdownContentElement.querySelectorAll('[data-kt-select-option]');
13275
13487
  }
13276
13488
  }
13277
13489
  // Sync selection after rebuilding
@@ -13337,12 +13549,8 @@ var KTSelect = /** @class */ (function (_super) {
13337
13549
  ? this._config.clearAllText
13338
13550
  : this._config.selectAllText;
13339
13551
  };
13340
- /**
13341
- * ========================================================================
13342
- * STATIC METHODS
13343
- * ========================================================================
13344
- */
13345
- KTSelect._instances = new Map();
13552
+ // Static global configuration
13553
+ KTSelect.globalConfig = {};
13346
13554
  return KTSelect;
13347
13555
  }(component_1.default));
13348
13556
  exports.KTSelect = KTSelect;