WI custom styling for regex keys

- WI custom style for regex keys
- moved select2 styling to its own file
This commit is contained in:
Wolfsblvt
2024-05-07 05:44:18 +02:00
parent 5a45e64999
commit fda0e886e4
6 changed files with 127 additions and 65 deletions

View File

@ -1450,6 +1450,18 @@ export function includesIgnoreCaseAndAccents(text, searchTerm) {
return normalizedText.includes(normalizedSearchTerm);
}
/**
* Returns a unique hash as ID for a select2 option text
*
* @param {string} option - The option
* @returns {string} A hashed version of that option
*/
export function getSelect2OptionId(option) {
return String(getStringHash(option));
}
/**
* Modifies the select2 options by adding not existing one and optionally selecting them
*
@ -1462,7 +1474,7 @@ export function includesIgnoreCaseAndAccents(text, searchTerm) {
export function select2ModifyOptions(element, items, { select = false, changeEventArgs = null } = {}) {
if (!items.length) return;
/** @type {{id: string, text: string}[]} */
const dataItems = items.map(x => typeof x === 'string' ? { id: x, text: x } : x);
const dataItems = items.map(x => typeof x === 'string' ? { id: getSelect2OptionId(x), text: x } : x);
dataItems.forEach(item => {
// Set the value, creating a new option if necessary