@keenthemes/ktui 1.0.24 → 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 +146 -7
- package/dist/ktui.min.js +1 -1
- package/dist/ktui.min.js.map +1 -1
- package/dist/styles.css +109 -11
- package/examples/select/dark-mode-test.html +93 -0
- package/examples/select/dropdowncontainer-test.html +111 -0
- package/examples/select/dynamic-methods.html +273 -0
- package/examples/select/remote-data-preselected.html +283 -0
- package/lib/cjs/components/select/select.js +146 -7
- package/lib/cjs/components/select/select.js.map +1 -1
- package/lib/esm/components/select/select.js +146 -7
- package/lib/esm/components/select/select.js.map +1 -1
- package/package.json +1 -1
- package/src/components/select/select.css +4 -4
- package/src/components/select/select.ts +199 -15
package/dist/ktui.js
CHANGED
|
@@ -11660,6 +11660,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
11660
11660
|
_this._selectAllButtonToggle = null;
|
|
11661
11661
|
_this._typeToSearchBuffer = new utils_1.TypeToSearchBuffer();
|
|
11662
11662
|
_this._mutationObserver = null;
|
|
11663
|
+
_this._preSelectedValues = [];
|
|
11663
11664
|
// Search debounce timeout
|
|
11664
11665
|
_this._searchDebounceTimeout = null;
|
|
11665
11666
|
// Store original options HTML for restoring after search
|
|
@@ -11773,6 +11774,14 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
11773
11774
|
* Clear existing options from the select element
|
|
11774
11775
|
*/
|
|
11775
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
|
+
}
|
|
11776
11785
|
// Keep only the empty/placeholder option and remove the rest
|
|
11777
11786
|
var options = Array.from(this._element.querySelectorAll('option:not([value=""])'));
|
|
11778
11787
|
options.forEach(function (option) { return option.remove(); });
|
|
@@ -11829,7 +11838,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
11829
11838
|
// Batch append all options at once
|
|
11830
11839
|
optionsContainer.appendChild(fragment);
|
|
11831
11840
|
// Update options NodeList
|
|
11832
|
-
this._options = this.
|
|
11841
|
+
this._options = this._dropdownContentElement.querySelectorAll('[data-kt-select-option]');
|
|
11833
11842
|
if (this._config.debug) {
|
|
11834
11843
|
console.log("Rendered ".concat(optionsData.length, " options in dropdown"));
|
|
11835
11844
|
}
|
|
@@ -11849,6 +11858,47 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
11849
11858
|
KTSelect.prototype._completeRemoteSetup = function () {
|
|
11850
11859
|
// Initialize options
|
|
11851
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
|
+
}
|
|
11852
11902
|
// Apply disabled state if needed
|
|
11853
11903
|
this._applyInitialDisabledState();
|
|
11854
11904
|
// Initialize search if enabled
|
|
@@ -12032,7 +12082,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12032
12082
|
}
|
|
12033
12083
|
});
|
|
12034
12084
|
// Update options NodeList to include the new options
|
|
12035
|
-
this._options = this.
|
|
12085
|
+
this._options = this._dropdownContentElement.querySelectorAll("[data-kt-select-option]");
|
|
12036
12086
|
if (this._config.debug)
|
|
12037
12087
|
console.log("Added ".concat(newItems.length, " more options to dropdown"));
|
|
12038
12088
|
};
|
|
@@ -12176,7 +12226,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12176
12226
|
this._selectAllButton = this._wrapperElement.querySelector('[data-kt-select-select-all]');
|
|
12177
12227
|
// Cache the options container for performance
|
|
12178
12228
|
this._optionsContainer = this._dropdownContentElement.querySelector('[data-kt-select-options]');
|
|
12179
|
-
this._options = this.
|
|
12229
|
+
this._options = this._dropdownContentElement.querySelectorAll("[data-kt-select-option]");
|
|
12180
12230
|
};
|
|
12181
12231
|
/**
|
|
12182
12232
|
* Attach all event listeners to elements
|
|
@@ -12546,7 +12596,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12546
12596
|
*/
|
|
12547
12597
|
KTSelect.prototype._updateSelectedOptionClass = function () {
|
|
12548
12598
|
var _this = this;
|
|
12549
|
-
var allOptions = this.
|
|
12599
|
+
var allOptions = this._dropdownContentElement.querySelectorAll("[data-kt-select-option]");
|
|
12550
12600
|
var selectedValues = this._state.getSelectedOptions();
|
|
12551
12601
|
var maxReached = typeof this._config.maxSelections === 'number' &&
|
|
12552
12602
|
selectedValues.length >= this._config.maxSelections;
|
|
@@ -12759,7 +12809,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12759
12809
|
*/
|
|
12760
12810
|
KTSelect.prototype.showAllOptions = function () {
|
|
12761
12811
|
// Get all options in the dropdown
|
|
12762
|
-
var options = Array.from(this.
|
|
12812
|
+
var options = Array.from(this._dropdownContentElement.querySelectorAll("[data-kt-select-option]"));
|
|
12763
12813
|
// Show all options by removing the hidden class and any inline styles
|
|
12764
12814
|
options.forEach(function (option) {
|
|
12765
12815
|
var _a;
|
|
@@ -12906,6 +12956,95 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
12906
12956
|
// Call parent dispose to clean up data
|
|
12907
12957
|
_super.prototype.dispose.call(this);
|
|
12908
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
|
+
};
|
|
12909
13048
|
/**
|
|
12910
13049
|
* ========================================================================
|
|
12911
13050
|
* STATIC METHODS
|
|
@@ -13039,7 +13178,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
13039
13178
|
// Restore original options
|
|
13040
13179
|
optionsContainer.innerHTML = this._originalOptionsHtml;
|
|
13041
13180
|
// Update options NodeList
|
|
13042
|
-
this._options = this.
|
|
13181
|
+
this._options = this._dropdownContentElement.querySelectorAll('[data-kt-select-option]');
|
|
13043
13182
|
// Refresh search module
|
|
13044
13183
|
if (this._searchModule) {
|
|
13045
13184
|
this._searchModule.refreshAfterSearch();
|
|
@@ -13344,7 +13483,7 @@ var KTSelect = /** @class */ (function (_super) {
|
|
|
13344
13483
|
optionsContainer_1.appendChild(renderedOption);
|
|
13345
13484
|
});
|
|
13346
13485
|
// Update internal references
|
|
13347
|
-
this._options = this.
|
|
13486
|
+
this._options = this._dropdownContentElement.querySelectorAll('[data-kt-select-option]');
|
|
13348
13487
|
}
|
|
13349
13488
|
}
|
|
13350
13489
|
// Sync selection after rebuilding
|