@smilodon/core 1.9.1-debug.0 → 1.9.1
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/README.md +4 -0
- package/dist/index.cjs +287 -113
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +285 -114
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.umd.js +287 -113
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/components/enhanced-select.d.ts +10 -0
- package/dist/types/src/components/select-option.d.ts +9 -1
- package/dist/types/src/config/global-config.d.ts +24 -19
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/utils/value-equality.d.ts +9 -0
- package/dist/types/src/utils/worker-manager.d.ts +4 -0
- package/dist/types/tests/lifecycle.spec.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
|
|
13
13
|
## 📖 Documentation
|
|
14
14
|
|
|
15
|
+
**Live documentation & interactive examples:** [navidrezadoost.github.io/Smilodon](https://navidrezadoost.github.io/Smilodon/)
|
|
16
|
+
|
|
17
|
+
**Framework integration (Vue 3, Nuxt 4, React, SSR, Vite):** [`docs/FRAMEWORK-INTEGRATION.md`](../../docs/FRAMEWORK-INTEGRATION.md)
|
|
18
|
+
|
|
15
19
|
**For comprehensive documentation covering all features, styling options, and advanced patterns:**
|
|
16
20
|
|
|
17
21
|
👉 **[Complete Vanilla JS Guide](../vanilla/COMPLETE-GUIDE.md)** 👈
|
package/dist/index.cjs
CHANGED
|
@@ -1089,12 +1089,16 @@ class NativeSelectElement extends HTMLElement {
|
|
|
1089
1089
|
* Returns single value for single-select, array for multi-select
|
|
1090
1090
|
*/
|
|
1091
1091
|
getValue() {
|
|
1092
|
-
|
|
1092
|
+
// Optimized: single-pass iteration, no intermediate arrays
|
|
1093
|
+
const values = [];
|
|
1094
|
+
for (const item of this._selectedItems.values()) {
|
|
1093
1095
|
if (typeof item === 'object' && item !== null && 'value' in item) {
|
|
1094
|
-
|
|
1096
|
+
values.push(item.value);
|
|
1095
1097
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
+
else {
|
|
1099
|
+
values.push(item);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1098
1102
|
return this._multi ? values : (values[0] ?? null);
|
|
1099
1103
|
}
|
|
1100
1104
|
render() {
|
|
@@ -1240,10 +1244,17 @@ class NativeSelectElement extends HTMLElement {
|
|
|
1240
1244
|
selected,
|
|
1241
1245
|
multi: this._multi
|
|
1242
1246
|
});
|
|
1247
|
+
// Optimized: single-pass iteration for change event data
|
|
1248
|
+
const selectedItems = [];
|
|
1249
|
+
const selectedValues = [];
|
|
1250
|
+
for (const item of this._selectedItems.values()) {
|
|
1251
|
+
selectedItems.push(item);
|
|
1252
|
+
selectedValues.push(item?.value ?? item);
|
|
1253
|
+
}
|
|
1243
1254
|
// Emit 'change' event for better React compatibility
|
|
1244
1255
|
this._emit('change', {
|
|
1245
|
-
selectedItems
|
|
1246
|
-
selectedValues
|
|
1256
|
+
selectedItems,
|
|
1257
|
+
selectedValues,
|
|
1247
1258
|
selectedIndices: Array.from(this._selectedSet)
|
|
1248
1259
|
});
|
|
1249
1260
|
this._announce(`Selected ${label}`);
|
|
@@ -1477,7 +1488,10 @@ class SelectConfigManager {
|
|
|
1477
1488
|
}
|
|
1478
1489
|
deepMerge(target, source) {
|
|
1479
1490
|
const result = { ...target };
|
|
1480
|
-
|
|
1491
|
+
// PERF: Avoid for...in, use Object.keys for predictable iteration
|
|
1492
|
+
const keys = Object.keys(source);
|
|
1493
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1494
|
+
const key = keys[i];
|
|
1481
1495
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1482
1496
|
const sourceValue = source[key];
|
|
1483
1497
|
const targetValue = result[key];
|
|
@@ -1516,15 +1530,33 @@ function resetSelectConfig() {
|
|
|
1516
1530
|
class SelectOption extends HTMLElement {
|
|
1517
1531
|
constructor(config) {
|
|
1518
1532
|
super();
|
|
1533
|
+
this._hasRendered = false;
|
|
1519
1534
|
this._config = config;
|
|
1520
1535
|
this._shadow = this.attachShadow({ mode: 'open' });
|
|
1521
1536
|
this._container = document.createElement('div');
|
|
1522
1537
|
this._container.className = 'option-container';
|
|
1523
1538
|
this._initializeStyles();
|
|
1524
|
-
|
|
1539
|
+
// NOTE: _render() moved to connectedCallback to comply with Web Components spec
|
|
1540
|
+
// (cannot mutate host element attributes/classes in constructor)
|
|
1525
1541
|
this._attachEventListeners();
|
|
1526
1542
|
this._shadow.appendChild(this._container);
|
|
1527
1543
|
}
|
|
1544
|
+
connectedCallback() {
|
|
1545
|
+
this._ensureRendered();
|
|
1546
|
+
}
|
|
1547
|
+
_ensureRendered() {
|
|
1548
|
+
if (this._hasRendered)
|
|
1549
|
+
return;
|
|
1550
|
+
this._render();
|
|
1551
|
+
this._hasRendered = true;
|
|
1552
|
+
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Ensure option content is rendered. Called by EnhancedSelect after append
|
|
1555
|
+
* when connectedCallback timing is unreliable (Vue/Nuxt, jsdom, Teleport).
|
|
1556
|
+
*/
|
|
1557
|
+
ensureRendered() {
|
|
1558
|
+
this._ensureRendered();
|
|
1559
|
+
}
|
|
1528
1560
|
_initializeStyles() {
|
|
1529
1561
|
const style = document.createElement('style');
|
|
1530
1562
|
style.textContent = `
|
|
@@ -2012,21 +2044,27 @@ class SelectOption extends HTMLElement {
|
|
|
2012
2044
|
*/
|
|
2013
2045
|
setSelected(selected) {
|
|
2014
2046
|
this._config.selected = selected;
|
|
2015
|
-
this.
|
|
2047
|
+
if (this._hasRendered) {
|
|
2048
|
+
this._render();
|
|
2049
|
+
}
|
|
2016
2050
|
}
|
|
2017
2051
|
/**
|
|
2018
2052
|
* Set active state
|
|
2019
2053
|
*/
|
|
2020
2054
|
setActive(active) {
|
|
2021
2055
|
this._config.active = active && (!this._config.disabled || this._getDisabledBehavior().focusable);
|
|
2022
|
-
this.
|
|
2056
|
+
if (this._hasRendered) {
|
|
2057
|
+
this._render();
|
|
2058
|
+
}
|
|
2023
2059
|
}
|
|
2024
2060
|
/**
|
|
2025
2061
|
* Set disabled state
|
|
2026
2062
|
*/
|
|
2027
2063
|
setDisabled(disabled) {
|
|
2028
2064
|
this._config.disabled = disabled;
|
|
2029
|
-
this.
|
|
2065
|
+
if (this._hasRendered) {
|
|
2066
|
+
this._render();
|
|
2067
|
+
}
|
|
2030
2068
|
}
|
|
2031
2069
|
}
|
|
2032
2070
|
// Register custom element
|
|
@@ -2034,6 +2072,42 @@ if (!customElements.get('select-option')) {
|
|
|
2034
2072
|
customElements.define('select-option', SelectOption);
|
|
2035
2073
|
}
|
|
2036
2074
|
|
|
2075
|
+
/**
|
|
2076
|
+
* Compare select item values with loose primitive coercion.
|
|
2077
|
+
* Treats string/number pairs like `"1"` and `1` as equal.
|
|
2078
|
+
*/
|
|
2079
|
+
function valuesEqual(a, b) {
|
|
2080
|
+
if (Object.is(a, b))
|
|
2081
|
+
return true;
|
|
2082
|
+
if (a == null || b == null)
|
|
2083
|
+
return false;
|
|
2084
|
+
if (typeof a === 'string' && typeof b === 'number') {
|
|
2085
|
+
return a === String(b);
|
|
2086
|
+
}
|
|
2087
|
+
if (typeof a === 'number' && typeof b === 'string') {
|
|
2088
|
+
return String(a) === b;
|
|
2089
|
+
}
|
|
2090
|
+
return false;
|
|
2091
|
+
}
|
|
2092
|
+
/** Returns true when `values` contains a value equal to `target`. */
|
|
2093
|
+
function arrayIncludesValue(values, target) {
|
|
2094
|
+
for (let i = 0; i < values.length; i += 1) {
|
|
2095
|
+
if (valuesEqual(values[i], target))
|
|
2096
|
+
return true;
|
|
2097
|
+
}
|
|
2098
|
+
return false;
|
|
2099
|
+
}
|
|
2100
|
+
/** Returns true when two value arrays match positionally with loose equality. */
|
|
2101
|
+
function arraysEqualByValue(a, b) {
|
|
2102
|
+
if (a.length !== b.length)
|
|
2103
|
+
return false;
|
|
2104
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
2105
|
+
if (!valuesEqual(a[i], b[i]))
|
|
2106
|
+
return false;
|
|
2107
|
+
}
|
|
2108
|
+
return true;
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2037
2111
|
/**
|
|
2038
2112
|
* Enhanced Select Component
|
|
2039
2113
|
* Implements all advanced features: infinite scroll, load more, busy state,
|
|
@@ -2138,7 +2212,8 @@ class EnhancedSelect extends HTMLElement {
|
|
|
2138
2212
|
// Initialize styles BEFORE assembling DOM (order matters in shadow DOM)
|
|
2139
2213
|
this._initializeStyles();
|
|
2140
2214
|
this._syncStyleConfigVariables();
|
|
2141
|
-
|
|
2215
|
+
// NOTE: _syncDirectionConfig moved to connectedCallback to comply with Web Components spec
|
|
2216
|
+
// (cannot call setAttribute on host element in constructor)
|
|
2142
2217
|
this._assembleDOM();
|
|
2143
2218
|
this._attachEventListeners();
|
|
2144
2219
|
this._initializeObservers();
|
|
@@ -2150,6 +2225,8 @@ class EnhancedSelect extends HTMLElement {
|
|
|
2150
2225
|
// Angular's rendering seems to not apply :host styles correctly in some cases
|
|
2151
2226
|
// Must be done in connectedCallback when element is attached to DOM
|
|
2152
2227
|
this.style.display = 'block';
|
|
2228
|
+
// Sync direction attribute (must be in connectedCallback, not constructor)
|
|
2229
|
+
this._syncDirectionConfig();
|
|
2153
2230
|
if (this._optionRenderer) {
|
|
2154
2231
|
this._setGlobalStylesMirroring(true);
|
|
2155
2232
|
}
|
|
@@ -2157,6 +2234,12 @@ class EnhancedSelect extends HTMLElement {
|
|
|
2157
2234
|
if (this._config.serverSide.enabled && this._config.serverSide.initialSelectedValues) {
|
|
2158
2235
|
this._loadInitialSelectedItems();
|
|
2159
2236
|
}
|
|
2237
|
+
// Re-render options after connect so SelectOption instances created while
|
|
2238
|
+
// disconnected (common in Vue/Nuxt client mounting) receive connectedCallback.
|
|
2239
|
+
if (this._state.loadedItems.length > 0 || this._state.groupedItems.length > 0) {
|
|
2240
|
+
this._renderOptions();
|
|
2241
|
+
this._updateInputDisplay();
|
|
2242
|
+
}
|
|
2160
2243
|
// Emit open event if configured to start open
|
|
2161
2244
|
if (this._config.callbacks.onOpen) {
|
|
2162
2245
|
this._config.callbacks.onOpen();
|
|
@@ -2339,16 +2422,47 @@ class EnhancedSelect extends HTMLElement {
|
|
|
2339
2422
|
if (!cssText.trim())
|
|
2340
2423
|
return '';
|
|
2341
2424
|
try {
|
|
2342
|
-
if (typeof CSSStyleSheet !== 'undefined') {
|
|
2425
|
+
if (typeof CSSStyleSheet !== 'undefined' && 'replaceSync' in CSSStyleSheet.prototype) {
|
|
2343
2426
|
const sheet = new CSSStyleSheet();
|
|
2344
2427
|
sheet.replaceSync(cssText);
|
|
2345
2428
|
return this._serializeScopedCssRules(Array.from(sheet.cssRules));
|
|
2346
2429
|
}
|
|
2347
2430
|
}
|
|
2348
2431
|
catch (_error) {
|
|
2432
|
+
// CSSStyleSheet API failed, use fallback parser for test environments (JSDOM)
|
|
2433
|
+
return this._scopeMirroredCssTextFallback(cssText);
|
|
2434
|
+
}
|
|
2435
|
+
// Fallback for environments without CSSStyleSheet.replaceSync
|
|
2436
|
+
return this._scopeMirroredCssTextFallback(cssText);
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* Fallback CSS parser for environments where CSSStyleSheet API is unavailable (e.g., JSDOM).
|
|
2440
|
+
* Performs simple text-based CSS rule scoping.
|
|
2441
|
+
*/
|
|
2442
|
+
_scopeMirroredCssTextFallback(cssText) {
|
|
2443
|
+
if (!cssText.trim())
|
|
2349
2444
|
return '';
|
|
2445
|
+
const result = [];
|
|
2446
|
+
// Match CSS rules with a simple regex (handles basic cases for testing)
|
|
2447
|
+
// This won't handle all edge cases but works for common CSS patterns
|
|
2448
|
+
const ruleRegex = /([^{}]+)\{([^{}]+)\}/g;
|
|
2449
|
+
let match;
|
|
2450
|
+
while ((match = ruleRegex.exec(cssText)) !== null) {
|
|
2451
|
+
const selectorText = match[1].trim();
|
|
2452
|
+
const declarations = match[2].trim();
|
|
2453
|
+
// Skip @-rules (media, keyframes, etc.) - would need more complex parsing
|
|
2454
|
+
if (selectorText.startsWith('@')) {
|
|
2455
|
+
continue;
|
|
2456
|
+
}
|
|
2457
|
+
// Split multiple selectors and scope each one
|
|
2458
|
+
const selectors = this._splitSelectorList(selectorText)
|
|
2459
|
+
.map((selector) => this._scopeMirroredSelector(selector))
|
|
2460
|
+
.filter(Boolean);
|
|
2461
|
+
if (selectors.length > 0) {
|
|
2462
|
+
result.push(`${selectors.join(', ')} { ${declarations} }`);
|
|
2463
|
+
}
|
|
2350
2464
|
}
|
|
2351
|
-
return '';
|
|
2465
|
+
return result.join('\n');
|
|
2352
2466
|
}
|
|
2353
2467
|
_serializeScopedCssRules(rules) {
|
|
2354
2468
|
return rules.map((rule) => this._serializeScopedCssRule(rule)).filter(Boolean).join('\n');
|
|
@@ -2735,6 +2849,8 @@ class EnhancedSelect extends HTMLElement {
|
|
|
2735
2849
|
this._dropdown.setAttribute('data-placement', this._resolvedDropdownPlacement);
|
|
2736
2850
|
}
|
|
2737
2851
|
_syncDirectionConfig() {
|
|
2852
|
+
if (!this.isConnected)
|
|
2853
|
+
return;
|
|
2738
2854
|
this.setAttribute('dir', this._config.direction ?? 'ltr');
|
|
2739
2855
|
}
|
|
2740
2856
|
_setIconContent(target, markup, fallback) {
|
|
@@ -3011,7 +3127,13 @@ class EnhancedSelect extends HTMLElement {
|
|
|
3011
3127
|
const icon = document.createElement('span');
|
|
3012
3128
|
icon.className = 'clear-control-icon';
|
|
3013
3129
|
icon.setAttribute('part', 'clear-icon');
|
|
3014
|
-
|
|
3130
|
+
// Use config icon if provided, otherwise default SVG
|
|
3131
|
+
if (this._config.clearControl.icon) {
|
|
3132
|
+
icon.textContent = this._config.clearControl.icon;
|
|
3133
|
+
}
|
|
3134
|
+
else {
|
|
3135
|
+
icon.innerHTML = `<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 4L4 12M4 4L12 12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
|
|
3136
|
+
}
|
|
3015
3137
|
button.setAttribute('aria-label', this._config.clearControl.ariaLabel || 'Clear selection and search');
|
|
3016
3138
|
button.appendChild(icon);
|
|
3017
3139
|
this._clearControlIcon = icon;
|
|
@@ -3604,8 +3726,8 @@ class EnhancedSelect extends HTMLElement {
|
|
|
3604
3726
|
top: 0;
|
|
3605
3727
|
right: 0;
|
|
3606
3728
|
bottom: 0;
|
|
3607
|
-
width: var(--select-arrow-width, 42px);
|
|
3608
|
-
height: var(--select-arrow-height, auto);
|
|
3729
|
+
width: var(--select-arrow-width, var(--select-arrow-size, 42px));
|
|
3730
|
+
height: var(--select-arrow-height, var(--select-arrow-size, auto));
|
|
3609
3731
|
display: flex;
|
|
3610
3732
|
align-items: center;
|
|
3611
3733
|
justify-content: center;
|
|
@@ -3709,8 +3831,8 @@ class EnhancedSelect extends HTMLElement {
|
|
|
3709
3831
|
}
|
|
3710
3832
|
|
|
3711
3833
|
.dropdown-arrow {
|
|
3712
|
-
width: var(--select-arrow-size,
|
|
3713
|
-
height: var(--select-arrow-size,
|
|
3834
|
+
width: var(--select-arrow-width, var(--select-arrow-size, 16px));
|
|
3835
|
+
height: var(--select-arrow-height, var(--select-arrow-size, 16px));
|
|
3714
3836
|
color: var(--select-arrow-color, var(--select-text-muted));
|
|
3715
3837
|
transition:
|
|
3716
3838
|
transform var(--select-transition-smooth),
|
|
@@ -3723,7 +3845,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
3723
3845
|
}
|
|
3724
3846
|
|
|
3725
3847
|
.dropdown-arrow-container:hover .dropdown-arrow {
|
|
3726
|
-
color: var(--select-arrow-hover
|
|
3848
|
+
color: var(--select-arrow-hover, var(--select-arrow-hover-color, #667eea));
|
|
3727
3849
|
}
|
|
3728
3850
|
|
|
3729
3851
|
.dropdown-arrow.open {
|
|
@@ -4387,7 +4509,8 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4387
4509
|
:host-context([darkmode]) .group-header,
|
|
4388
4510
|
:host-context([data-theme="dark"]) .group-header,
|
|
4389
4511
|
:host-context([theme="dark"]) .group-header {
|
|
4390
|
-
|
|
4512
|
+
color: var(--select-dark-group-header-color, var(--select-group-header-color, inherit));
|
|
4513
|
+
background: var(--select-dark-group-header-bg, var(--select-group-header-bg, #1a1a2e));
|
|
4391
4514
|
border-bottom: var(--select-group-header-border-bottom, 1px solid rgba(255, 255, 255, 0.08));
|
|
4392
4515
|
box-shadow: var(--select-group-header-shadow, 0 1px 2px rgba(0, 0, 0, 0.3));
|
|
4393
4516
|
}
|
|
@@ -4880,6 +5003,41 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4880
5003
|
this._perfMeasure('smilodon-search-to-render', 'smilodon-search-input-last', 'smilodon-search-render-complete');
|
|
4881
5004
|
}
|
|
4882
5005
|
}
|
|
5006
|
+
/**
|
|
5007
|
+
* Filter items by search query (optimized hot path)
|
|
5008
|
+
* Uses for-loop with hoisted invariants for better performance
|
|
5009
|
+
*/
|
|
5010
|
+
_filterItemsByQuery(items, query) {
|
|
5011
|
+
// Early return for empty query
|
|
5012
|
+
if (!query?.trim())
|
|
5013
|
+
return items;
|
|
5014
|
+
// PERF: Hoist invariants outside loop
|
|
5015
|
+
const lowerQuery = query.toLowerCase().trim();
|
|
5016
|
+
const getLabelFn = this._config.serverSide.getLabelFromItem
|
|
5017
|
+
?? ((item) => item?.label ?? item?.text ?? String(item));
|
|
5018
|
+
const results = [];
|
|
5019
|
+
const len = items.length;
|
|
5020
|
+
// PERF: for-loop instead of filter (no closure allocation)
|
|
5021
|
+
for (let i = 0; i < len; i++) {
|
|
5022
|
+
const item = items[i];
|
|
5023
|
+
if (item == null)
|
|
5024
|
+
continue;
|
|
5025
|
+
try {
|
|
5026
|
+
const label = getLabelFn(item);
|
|
5027
|
+
if (label == null)
|
|
5028
|
+
continue;
|
|
5029
|
+
const labelStr = String(label).toLowerCase();
|
|
5030
|
+
if (labelStr.includes(lowerQuery)) {
|
|
5031
|
+
results.push(item);
|
|
5032
|
+
}
|
|
5033
|
+
}
|
|
5034
|
+
catch (e) {
|
|
5035
|
+
// Silent fail for robustness with external data
|
|
5036
|
+
continue;
|
|
5037
|
+
}
|
|
5038
|
+
}
|
|
5039
|
+
return results;
|
|
5040
|
+
}
|
|
4883
5041
|
_handleSearch(query) {
|
|
4884
5042
|
this._state.searchQuery = query;
|
|
4885
5043
|
this._syncClearControlState();
|
|
@@ -4905,25 +5063,12 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4905
5063
|
// Filter and render options immediately
|
|
4906
5064
|
this._renderOptions();
|
|
4907
5065
|
}
|
|
4908
|
-
//
|
|
4909
|
-
const
|
|
4910
|
-
// FIX: Do not trim query to allow searching for phrases with spaces
|
|
4911
|
-
const searchQuery = query.toLowerCase();
|
|
4912
|
-
const filteredItems = searchQuery
|
|
4913
|
-
? this._state.loadedItems.filter((item) => {
|
|
4914
|
-
try {
|
|
4915
|
-
const label = String(getLabel(item)).toLowerCase();
|
|
4916
|
-
// Match the entire search phrase
|
|
4917
|
-
return label.includes(searchQuery);
|
|
4918
|
-
}
|
|
4919
|
-
catch (e) {
|
|
4920
|
-
return false;
|
|
4921
|
-
}
|
|
4922
|
-
})
|
|
4923
|
-
: this._state.loadedItems;
|
|
5066
|
+
// PERF: Use optimized filter function
|
|
5067
|
+
const filteredItems = this._filterItemsByQuery(this._state.loadedItems, query);
|
|
4924
5068
|
const count = filteredItems.length;
|
|
4925
5069
|
// Announce search results for accessibility
|
|
4926
|
-
|
|
5070
|
+
const trimmedQuery = query.trim();
|
|
5071
|
+
if (trimmedQuery) {
|
|
4927
5072
|
this._announce(`${count} result${count !== 1 ? 's' : ''} found for "${query}"`);
|
|
4928
5073
|
}
|
|
4929
5074
|
// Only notify if query or result count changed to prevent infinite loops
|
|
@@ -5772,7 +5917,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
5772
5917
|
this._state.selectedIndices.clear();
|
|
5773
5918
|
this._state.selectedItems.clear();
|
|
5774
5919
|
this._state.loadedItems.forEach((item, index) => {
|
|
5775
|
-
if (values
|
|
5920
|
+
if (arrayIncludesValue(values, getValue(item)) && !this._isOptionSelectionBlocked(item)) {
|
|
5776
5921
|
this._state.selectedIndices.add(index);
|
|
5777
5922
|
this._state.selectedItems.set(index, item);
|
|
5778
5923
|
}
|
|
@@ -5883,7 +6028,13 @@ class EnhancedSelect extends HTMLElement {
|
|
|
5883
6028
|
this._clearControl.setAttribute('aria-label', this._config.clearControl.ariaLabel || 'Clear selection and search');
|
|
5884
6029
|
}
|
|
5885
6030
|
if (this._clearControlIcon) {
|
|
5886
|
-
|
|
6031
|
+
// Use config icon if provided, otherwise default SVG
|
|
6032
|
+
if (this._config.clearControl.icon) {
|
|
6033
|
+
this._clearControlIcon.textContent = this._config.clearControl.icon;
|
|
6034
|
+
}
|
|
6035
|
+
else {
|
|
6036
|
+
this._clearControlIcon.innerHTML = `<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 4L4 12M4 4L12 12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
|
|
6037
|
+
}
|
|
5887
6038
|
}
|
|
5888
6039
|
this._syncStyleConfigVariables();
|
|
5889
6040
|
if (this._dropdown) {
|
|
@@ -5894,19 +6045,30 @@ class EnhancedSelect extends HTMLElement {
|
|
|
5894
6045
|
this._dropdown.removeAttribute('aria-multiselectable');
|
|
5895
6046
|
}
|
|
5896
6047
|
}
|
|
5897
|
-
this.
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
6048
|
+
if (this.isConnected) {
|
|
6049
|
+
this._syncDirectionConfig();
|
|
6050
|
+
this._syncInputContainerMode();
|
|
6051
|
+
this._syncMultiSelectDisplayConfig();
|
|
6052
|
+
this._syncDropdownPlacement();
|
|
6053
|
+
// Re-initialize observers in case infinite scroll was enabled/disabled
|
|
6054
|
+
this._initializeObservers();
|
|
6055
|
+
this._syncClearControlState();
|
|
6056
|
+
this._updateInputDisplay();
|
|
6057
|
+
this._renderOptions();
|
|
6058
|
+
}
|
|
6059
|
+
else {
|
|
6060
|
+
this._syncInputContainerMode();
|
|
6061
|
+
this._syncMultiSelectDisplayConfig();
|
|
6062
|
+
this._syncClearControlState();
|
|
6063
|
+
this._updateInputDisplay();
|
|
6064
|
+
}
|
|
5906
6065
|
}
|
|
5907
6066
|
_mergeConfig(target, source) {
|
|
5908
6067
|
const result = { ...target };
|
|
5909
|
-
|
|
6068
|
+
// PERF: Avoid for...in, use Object.keys for predictable iteration
|
|
6069
|
+
const keys = Object.keys(source);
|
|
6070
|
+
for (let i = 0; i < keys.length; i++) {
|
|
6071
|
+
const key = keys[i];
|
|
5910
6072
|
if (!Object.prototype.hasOwnProperty.call(source, key))
|
|
5911
6073
|
continue;
|
|
5912
6074
|
const sourceValue = source[key];
|
|
@@ -6248,6 +6410,9 @@ class EnhancedSelect extends HTMLElement {
|
|
|
6248
6410
|
this._handleOptionRemove(targetIndex);
|
|
6249
6411
|
});
|
|
6250
6412
|
targetContainer.appendChild(option);
|
|
6413
|
+
if (option instanceof SelectOption) {
|
|
6414
|
+
option.ensureRendered();
|
|
6415
|
+
}
|
|
6251
6416
|
}
|
|
6252
6417
|
_normalizeCustomOptionElement(element, meta) {
|
|
6253
6418
|
const optionEl = element instanceof HTMLElement ? element : document.createElement('div');
|
|
@@ -6424,6 +6589,58 @@ class WorkerManager {
|
|
|
6424
6589
|
this.supportsWorkers = false;
|
|
6425
6590
|
this.supportsSharedArrayBuffer = false;
|
|
6426
6591
|
this.nextId = 0;
|
|
6592
|
+
/**
|
|
6593
|
+
* Operation handlers for fallback execution
|
|
6594
|
+
*/
|
|
6595
|
+
this._fallbackOperations = {
|
|
6596
|
+
'transform': (payload) => {
|
|
6597
|
+
const { items, transformer } = payload;
|
|
6598
|
+
const fn = new Function('item', 'index', `return (${transformer})(item, index)`);
|
|
6599
|
+
return items.map((item, i) => fn(item, i));
|
|
6600
|
+
},
|
|
6601
|
+
'search': (payload) => {
|
|
6602
|
+
const { items, query, fuzzy } = payload;
|
|
6603
|
+
const lowerQuery = query.toLowerCase();
|
|
6604
|
+
const results = [];
|
|
6605
|
+
// Use for-loop instead of forEach for better performance (no closure allocation)
|
|
6606
|
+
for (let index = 0; index < items.length; index++) {
|
|
6607
|
+
const item = items[index];
|
|
6608
|
+
// PERF: Check for label/value properties first before converting entire object
|
|
6609
|
+
const itemAny = item;
|
|
6610
|
+
const itemText = itemAny?.label ?? itemAny?.value ?? item;
|
|
6611
|
+
const itemStr = String(itemText).toLowerCase();
|
|
6612
|
+
if (fuzzy) {
|
|
6613
|
+
// Simple fuzzy match - check if all query chars appear in order
|
|
6614
|
+
let queryIndex = 0;
|
|
6615
|
+
for (let i = 0; i < itemStr.length && queryIndex < lowerQuery.length; i++) {
|
|
6616
|
+
if (itemStr[i] === lowerQuery[queryIndex]) {
|
|
6617
|
+
queryIndex++;
|
|
6618
|
+
}
|
|
6619
|
+
}
|
|
6620
|
+
if (queryIndex === lowerQuery.length) {
|
|
6621
|
+
results.push({ item, index });
|
|
6622
|
+
}
|
|
6623
|
+
}
|
|
6624
|
+
else {
|
|
6625
|
+
// Exact substring match
|
|
6626
|
+
if (itemStr.includes(lowerQuery)) {
|
|
6627
|
+
results.push({ item, index });
|
|
6628
|
+
}
|
|
6629
|
+
}
|
|
6630
|
+
}
|
|
6631
|
+
return results;
|
|
6632
|
+
},
|
|
6633
|
+
'filter': (payload) => {
|
|
6634
|
+
const { items, predicate } = payload;
|
|
6635
|
+
const fn = new Function('item', 'index', `return (${predicate})(item, index)`);
|
|
6636
|
+
return items.filter((item, i) => fn(item, i));
|
|
6637
|
+
},
|
|
6638
|
+
'sort': (payload) => {
|
|
6639
|
+
const { items, comparator } = payload;
|
|
6640
|
+
const fn = new Function('a', 'b', `return (${comparator})(a, b)`);
|
|
6641
|
+
return [...items].sort(fn);
|
|
6642
|
+
},
|
|
6643
|
+
};
|
|
6427
6644
|
this.detectFeatures();
|
|
6428
6645
|
this.initWorker();
|
|
6429
6646
|
}
|
|
@@ -6465,27 +6682,23 @@ class WorkerManager {
|
|
|
6465
6682
|
const start = performance.now();
|
|
6466
6683
|
const { id, type, payload } = e.data;
|
|
6467
6684
|
|
|
6685
|
+
// Lookup object for O(1) operation dispatch
|
|
6686
|
+
const operations = {
|
|
6687
|
+
'transform': handleTransform,
|
|
6688
|
+
'search': handleSearch,
|
|
6689
|
+
'filter': handleFilter,
|
|
6690
|
+
'sort': handleSort,
|
|
6691
|
+
};
|
|
6692
|
+
|
|
6468
6693
|
try {
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
case 'transform':
|
|
6473
|
-
result = handleTransform(payload);
|
|
6474
|
-
break;
|
|
6475
|
-
case 'search':
|
|
6476
|
-
result = handleSearch(payload);
|
|
6477
|
-
break;
|
|
6478
|
-
case 'filter':
|
|
6479
|
-
result = handleFilter(payload);
|
|
6480
|
-
break;
|
|
6481
|
-
case 'sort':
|
|
6482
|
-
result = handleSort(payload);
|
|
6483
|
-
break;
|
|
6484
|
-
default:
|
|
6485
|
-
throw new Error('Unknown operation: ' + type);
|
|
6694
|
+
const handler = operations[type];
|
|
6695
|
+
if (!handler) {
|
|
6696
|
+
throw new Error('Unknown operation: ' + type);
|
|
6486
6697
|
}
|
|
6487
6698
|
|
|
6699
|
+
const result = handler(payload);
|
|
6488
6700
|
const duration = performance.now() - start;
|
|
6701
|
+
|
|
6489
6702
|
self.postMessage({
|
|
6490
6703
|
id,
|
|
6491
6704
|
success: true,
|
|
@@ -6617,53 +6830,11 @@ class WorkerManager {
|
|
|
6617
6830
|
* Fallback to main thread execution
|
|
6618
6831
|
*/
|
|
6619
6832
|
async executeFallback(type, payload) {
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
const { items, transformer } = payload;
|
|
6624
|
-
const fn = new Function('item', 'index', `return (${transformer})(item, index)`);
|
|
6625
|
-
return items.map((item, i) => fn(item, i));
|
|
6626
|
-
}
|
|
6627
|
-
case 'search': {
|
|
6628
|
-
const { items, query, fuzzy } = payload;
|
|
6629
|
-
const lowerQuery = query.toLowerCase();
|
|
6630
|
-
const results = [];
|
|
6631
|
-
items.forEach((item, index) => {
|
|
6632
|
-
const itemStr = String(item).toLowerCase();
|
|
6633
|
-
if (fuzzy) {
|
|
6634
|
-
// Simple fuzzy match - check if all query chars appear in order
|
|
6635
|
-
let queryIndex = 0;
|
|
6636
|
-
for (let i = 0; i < itemStr.length && queryIndex < lowerQuery.length; i++) {
|
|
6637
|
-
if (itemStr[i] === lowerQuery[queryIndex]) {
|
|
6638
|
-
queryIndex++;
|
|
6639
|
-
}
|
|
6640
|
-
}
|
|
6641
|
-
if (queryIndex === lowerQuery.length) {
|
|
6642
|
-
results.push({ item, index });
|
|
6643
|
-
}
|
|
6644
|
-
}
|
|
6645
|
-
else {
|
|
6646
|
-
// Exact substring match
|
|
6647
|
-
if (itemStr.includes(lowerQuery)) {
|
|
6648
|
-
results.push({ item, index });
|
|
6649
|
-
}
|
|
6650
|
-
}
|
|
6651
|
-
});
|
|
6652
|
-
return results;
|
|
6653
|
-
}
|
|
6654
|
-
case 'filter': {
|
|
6655
|
-
const { items, predicate } = payload;
|
|
6656
|
-
const fn = new Function('item', 'index', `return (${predicate})(item, index)`);
|
|
6657
|
-
return items.filter((item, i) => fn(item, i));
|
|
6658
|
-
}
|
|
6659
|
-
case 'sort': {
|
|
6660
|
-
const { items, comparator } = payload;
|
|
6661
|
-
const fn = new Function('a', 'b', `return (${comparator})(a, b)`);
|
|
6662
|
-
return [...items].sort(fn);
|
|
6663
|
-
}
|
|
6664
|
-
default:
|
|
6665
|
-
throw new Error(`Unknown operation: ${type}`);
|
|
6833
|
+
const handler = this._fallbackOperations[type];
|
|
6834
|
+
if (!handler) {
|
|
6835
|
+
throw new Error(`Unknown operation: ${type}`);
|
|
6666
6836
|
}
|
|
6837
|
+
return handler(payload);
|
|
6667
6838
|
}
|
|
6668
6839
|
/**
|
|
6669
6840
|
* Transform items with custom function
|
|
@@ -7427,6 +7598,8 @@ exports.Virtualizer = Virtualizer;
|
|
|
7427
7598
|
exports.WorkerManager = WorkerManager;
|
|
7428
7599
|
exports.applyClasses = applyClasses;
|
|
7429
7600
|
exports.applyDefaultTheme = applyDefaultTheme;
|
|
7601
|
+
exports.arrayIncludesValue = arrayIncludesValue;
|
|
7602
|
+
exports.arraysEqualByValue = arraysEqualByValue;
|
|
7430
7603
|
exports.configureSelect = configureSelect;
|
|
7431
7604
|
exports.containsSuspiciousPatterns = containsSuspiciousPatterns;
|
|
7432
7605
|
exports.createElement = createElement;
|
|
@@ -7456,5 +7629,6 @@ exports.setTextContent = setTextContent;
|
|
|
7456
7629
|
exports.shadowDOMStyles = shadowDOMStyles;
|
|
7457
7630
|
exports.toggleClass = toggleClass;
|
|
7458
7631
|
exports.validateTemplate = validateTemplate;
|
|
7632
|
+
exports.valuesEqual = valuesEqual;
|
|
7459
7633
|
exports.warnCSPViolation = warnCSPViolation;
|
|
7460
7634
|
//# sourceMappingURL=index.cjs.map
|