@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/dist/index.umd.js
CHANGED
|
@@ -1093,12 +1093,16 @@
|
|
|
1093
1093
|
* Returns single value for single-select, array for multi-select
|
|
1094
1094
|
*/
|
|
1095
1095
|
getValue() {
|
|
1096
|
-
|
|
1096
|
+
// Optimized: single-pass iteration, no intermediate arrays
|
|
1097
|
+
const values = [];
|
|
1098
|
+
for (const item of this._selectedItems.values()) {
|
|
1097
1099
|
if (typeof item === 'object' && item !== null && 'value' in item) {
|
|
1098
|
-
|
|
1100
|
+
values.push(item.value);
|
|
1099
1101
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
+
else {
|
|
1103
|
+
values.push(item);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1102
1106
|
return this._multi ? values : (values[0] ?? null);
|
|
1103
1107
|
}
|
|
1104
1108
|
render() {
|
|
@@ -1244,10 +1248,17 @@
|
|
|
1244
1248
|
selected,
|
|
1245
1249
|
multi: this._multi
|
|
1246
1250
|
});
|
|
1251
|
+
// Optimized: single-pass iteration for change event data
|
|
1252
|
+
const selectedItems = [];
|
|
1253
|
+
const selectedValues = [];
|
|
1254
|
+
for (const item of this._selectedItems.values()) {
|
|
1255
|
+
selectedItems.push(item);
|
|
1256
|
+
selectedValues.push(item?.value ?? item);
|
|
1257
|
+
}
|
|
1247
1258
|
// Emit 'change' event for better React compatibility
|
|
1248
1259
|
this._emit('change', {
|
|
1249
|
-
selectedItems
|
|
1250
|
-
selectedValues
|
|
1260
|
+
selectedItems,
|
|
1261
|
+
selectedValues,
|
|
1251
1262
|
selectedIndices: Array.from(this._selectedSet)
|
|
1252
1263
|
});
|
|
1253
1264
|
this._announce(`Selected ${label}`);
|
|
@@ -1481,7 +1492,10 @@
|
|
|
1481
1492
|
}
|
|
1482
1493
|
deepMerge(target, source) {
|
|
1483
1494
|
const result = { ...target };
|
|
1484
|
-
|
|
1495
|
+
// PERF: Avoid for...in, use Object.keys for predictable iteration
|
|
1496
|
+
const keys = Object.keys(source);
|
|
1497
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1498
|
+
const key = keys[i];
|
|
1485
1499
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1486
1500
|
const sourceValue = source[key];
|
|
1487
1501
|
const targetValue = result[key];
|
|
@@ -1520,15 +1534,33 @@
|
|
|
1520
1534
|
class SelectOption extends HTMLElement {
|
|
1521
1535
|
constructor(config) {
|
|
1522
1536
|
super();
|
|
1537
|
+
this._hasRendered = false;
|
|
1523
1538
|
this._config = config;
|
|
1524
1539
|
this._shadow = this.attachShadow({ mode: 'open' });
|
|
1525
1540
|
this._container = document.createElement('div');
|
|
1526
1541
|
this._container.className = 'option-container';
|
|
1527
1542
|
this._initializeStyles();
|
|
1528
|
-
|
|
1543
|
+
// NOTE: _render() moved to connectedCallback to comply with Web Components spec
|
|
1544
|
+
// (cannot mutate host element attributes/classes in constructor)
|
|
1529
1545
|
this._attachEventListeners();
|
|
1530
1546
|
this._shadow.appendChild(this._container);
|
|
1531
1547
|
}
|
|
1548
|
+
connectedCallback() {
|
|
1549
|
+
this._ensureRendered();
|
|
1550
|
+
}
|
|
1551
|
+
_ensureRendered() {
|
|
1552
|
+
if (this._hasRendered)
|
|
1553
|
+
return;
|
|
1554
|
+
this._render();
|
|
1555
|
+
this._hasRendered = true;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Ensure option content is rendered. Called by EnhancedSelect after append
|
|
1559
|
+
* when connectedCallback timing is unreliable (Vue/Nuxt, jsdom, Teleport).
|
|
1560
|
+
*/
|
|
1561
|
+
ensureRendered() {
|
|
1562
|
+
this._ensureRendered();
|
|
1563
|
+
}
|
|
1532
1564
|
_initializeStyles() {
|
|
1533
1565
|
const style = document.createElement('style');
|
|
1534
1566
|
style.textContent = `
|
|
@@ -2016,21 +2048,27 @@
|
|
|
2016
2048
|
*/
|
|
2017
2049
|
setSelected(selected) {
|
|
2018
2050
|
this._config.selected = selected;
|
|
2019
|
-
this.
|
|
2051
|
+
if (this._hasRendered) {
|
|
2052
|
+
this._render();
|
|
2053
|
+
}
|
|
2020
2054
|
}
|
|
2021
2055
|
/**
|
|
2022
2056
|
* Set active state
|
|
2023
2057
|
*/
|
|
2024
2058
|
setActive(active) {
|
|
2025
2059
|
this._config.active = active && (!this._config.disabled || this._getDisabledBehavior().focusable);
|
|
2026
|
-
this.
|
|
2060
|
+
if (this._hasRendered) {
|
|
2061
|
+
this._render();
|
|
2062
|
+
}
|
|
2027
2063
|
}
|
|
2028
2064
|
/**
|
|
2029
2065
|
* Set disabled state
|
|
2030
2066
|
*/
|
|
2031
2067
|
setDisabled(disabled) {
|
|
2032
2068
|
this._config.disabled = disabled;
|
|
2033
|
-
this.
|
|
2069
|
+
if (this._hasRendered) {
|
|
2070
|
+
this._render();
|
|
2071
|
+
}
|
|
2034
2072
|
}
|
|
2035
2073
|
}
|
|
2036
2074
|
// Register custom element
|
|
@@ -2038,6 +2076,42 @@
|
|
|
2038
2076
|
customElements.define('select-option', SelectOption);
|
|
2039
2077
|
}
|
|
2040
2078
|
|
|
2079
|
+
/**
|
|
2080
|
+
* Compare select item values with loose primitive coercion.
|
|
2081
|
+
* Treats string/number pairs like `"1"` and `1` as equal.
|
|
2082
|
+
*/
|
|
2083
|
+
function valuesEqual(a, b) {
|
|
2084
|
+
if (Object.is(a, b))
|
|
2085
|
+
return true;
|
|
2086
|
+
if (a == null || b == null)
|
|
2087
|
+
return false;
|
|
2088
|
+
if (typeof a === 'string' && typeof b === 'number') {
|
|
2089
|
+
return a === String(b);
|
|
2090
|
+
}
|
|
2091
|
+
if (typeof a === 'number' && typeof b === 'string') {
|
|
2092
|
+
return String(a) === b;
|
|
2093
|
+
}
|
|
2094
|
+
return false;
|
|
2095
|
+
}
|
|
2096
|
+
/** Returns true when `values` contains a value equal to `target`. */
|
|
2097
|
+
function arrayIncludesValue(values, target) {
|
|
2098
|
+
for (let i = 0; i < values.length; i += 1) {
|
|
2099
|
+
if (valuesEqual(values[i], target))
|
|
2100
|
+
return true;
|
|
2101
|
+
}
|
|
2102
|
+
return false;
|
|
2103
|
+
}
|
|
2104
|
+
/** Returns true when two value arrays match positionally with loose equality. */
|
|
2105
|
+
function arraysEqualByValue(a, b) {
|
|
2106
|
+
if (a.length !== b.length)
|
|
2107
|
+
return false;
|
|
2108
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
2109
|
+
if (!valuesEqual(a[i], b[i]))
|
|
2110
|
+
return false;
|
|
2111
|
+
}
|
|
2112
|
+
return true;
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2041
2115
|
/**
|
|
2042
2116
|
* Enhanced Select Component
|
|
2043
2117
|
* Implements all advanced features: infinite scroll, load more, busy state,
|
|
@@ -2142,7 +2216,8 @@
|
|
|
2142
2216
|
// Initialize styles BEFORE assembling DOM (order matters in shadow DOM)
|
|
2143
2217
|
this._initializeStyles();
|
|
2144
2218
|
this._syncStyleConfigVariables();
|
|
2145
|
-
|
|
2219
|
+
// NOTE: _syncDirectionConfig moved to connectedCallback to comply with Web Components spec
|
|
2220
|
+
// (cannot call setAttribute on host element in constructor)
|
|
2146
2221
|
this._assembleDOM();
|
|
2147
2222
|
this._attachEventListeners();
|
|
2148
2223
|
this._initializeObservers();
|
|
@@ -2154,6 +2229,8 @@
|
|
|
2154
2229
|
// Angular's rendering seems to not apply :host styles correctly in some cases
|
|
2155
2230
|
// Must be done in connectedCallback when element is attached to DOM
|
|
2156
2231
|
this.style.display = 'block';
|
|
2232
|
+
// Sync direction attribute (must be in connectedCallback, not constructor)
|
|
2233
|
+
this._syncDirectionConfig();
|
|
2157
2234
|
if (this._optionRenderer) {
|
|
2158
2235
|
this._setGlobalStylesMirroring(true);
|
|
2159
2236
|
}
|
|
@@ -2161,6 +2238,12 @@
|
|
|
2161
2238
|
if (this._config.serverSide.enabled && this._config.serverSide.initialSelectedValues) {
|
|
2162
2239
|
this._loadInitialSelectedItems();
|
|
2163
2240
|
}
|
|
2241
|
+
// Re-render options after connect so SelectOption instances created while
|
|
2242
|
+
// disconnected (common in Vue/Nuxt client mounting) receive connectedCallback.
|
|
2243
|
+
if (this._state.loadedItems.length > 0 || this._state.groupedItems.length > 0) {
|
|
2244
|
+
this._renderOptions();
|
|
2245
|
+
this._updateInputDisplay();
|
|
2246
|
+
}
|
|
2164
2247
|
// Emit open event if configured to start open
|
|
2165
2248
|
if (this._config.callbacks.onOpen) {
|
|
2166
2249
|
this._config.callbacks.onOpen();
|
|
@@ -2343,16 +2426,47 @@
|
|
|
2343
2426
|
if (!cssText.trim())
|
|
2344
2427
|
return '';
|
|
2345
2428
|
try {
|
|
2346
|
-
if (typeof CSSStyleSheet !== 'undefined') {
|
|
2429
|
+
if (typeof CSSStyleSheet !== 'undefined' && 'replaceSync' in CSSStyleSheet.prototype) {
|
|
2347
2430
|
const sheet = new CSSStyleSheet();
|
|
2348
2431
|
sheet.replaceSync(cssText);
|
|
2349
2432
|
return this._serializeScopedCssRules(Array.from(sheet.cssRules));
|
|
2350
2433
|
}
|
|
2351
2434
|
}
|
|
2352
2435
|
catch (_error) {
|
|
2436
|
+
// CSSStyleSheet API failed, use fallback parser for test environments (JSDOM)
|
|
2437
|
+
return this._scopeMirroredCssTextFallback(cssText);
|
|
2438
|
+
}
|
|
2439
|
+
// Fallback for environments without CSSStyleSheet.replaceSync
|
|
2440
|
+
return this._scopeMirroredCssTextFallback(cssText);
|
|
2441
|
+
}
|
|
2442
|
+
/**
|
|
2443
|
+
* Fallback CSS parser for environments where CSSStyleSheet API is unavailable (e.g., JSDOM).
|
|
2444
|
+
* Performs simple text-based CSS rule scoping.
|
|
2445
|
+
*/
|
|
2446
|
+
_scopeMirroredCssTextFallback(cssText) {
|
|
2447
|
+
if (!cssText.trim())
|
|
2353
2448
|
return '';
|
|
2449
|
+
const result = [];
|
|
2450
|
+
// Match CSS rules with a simple regex (handles basic cases for testing)
|
|
2451
|
+
// This won't handle all edge cases but works for common CSS patterns
|
|
2452
|
+
const ruleRegex = /([^{}]+)\{([^{}]+)\}/g;
|
|
2453
|
+
let match;
|
|
2454
|
+
while ((match = ruleRegex.exec(cssText)) !== null) {
|
|
2455
|
+
const selectorText = match[1].trim();
|
|
2456
|
+
const declarations = match[2].trim();
|
|
2457
|
+
// Skip @-rules (media, keyframes, etc.) - would need more complex parsing
|
|
2458
|
+
if (selectorText.startsWith('@')) {
|
|
2459
|
+
continue;
|
|
2460
|
+
}
|
|
2461
|
+
// Split multiple selectors and scope each one
|
|
2462
|
+
const selectors = this._splitSelectorList(selectorText)
|
|
2463
|
+
.map((selector) => this._scopeMirroredSelector(selector))
|
|
2464
|
+
.filter(Boolean);
|
|
2465
|
+
if (selectors.length > 0) {
|
|
2466
|
+
result.push(`${selectors.join(', ')} { ${declarations} }`);
|
|
2467
|
+
}
|
|
2354
2468
|
}
|
|
2355
|
-
return '';
|
|
2469
|
+
return result.join('\n');
|
|
2356
2470
|
}
|
|
2357
2471
|
_serializeScopedCssRules(rules) {
|
|
2358
2472
|
return rules.map((rule) => this._serializeScopedCssRule(rule)).filter(Boolean).join('\n');
|
|
@@ -2739,6 +2853,8 @@
|
|
|
2739
2853
|
this._dropdown.setAttribute('data-placement', this._resolvedDropdownPlacement);
|
|
2740
2854
|
}
|
|
2741
2855
|
_syncDirectionConfig() {
|
|
2856
|
+
if (!this.isConnected)
|
|
2857
|
+
return;
|
|
2742
2858
|
this.setAttribute('dir', this._config.direction ?? 'ltr');
|
|
2743
2859
|
}
|
|
2744
2860
|
_setIconContent(target, markup, fallback) {
|
|
@@ -3015,7 +3131,13 @@
|
|
|
3015
3131
|
const icon = document.createElement('span');
|
|
3016
3132
|
icon.className = 'clear-control-icon';
|
|
3017
3133
|
icon.setAttribute('part', 'clear-icon');
|
|
3018
|
-
|
|
3134
|
+
// Use config icon if provided, otherwise default SVG
|
|
3135
|
+
if (this._config.clearControl.icon) {
|
|
3136
|
+
icon.textContent = this._config.clearControl.icon;
|
|
3137
|
+
}
|
|
3138
|
+
else {
|
|
3139
|
+
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>`;
|
|
3140
|
+
}
|
|
3019
3141
|
button.setAttribute('aria-label', this._config.clearControl.ariaLabel || 'Clear selection and search');
|
|
3020
3142
|
button.appendChild(icon);
|
|
3021
3143
|
this._clearControlIcon = icon;
|
|
@@ -3608,8 +3730,8 @@
|
|
|
3608
3730
|
top: 0;
|
|
3609
3731
|
right: 0;
|
|
3610
3732
|
bottom: 0;
|
|
3611
|
-
width: var(--select-arrow-width, 42px);
|
|
3612
|
-
height: var(--select-arrow-height, auto);
|
|
3733
|
+
width: var(--select-arrow-width, var(--select-arrow-size, 42px));
|
|
3734
|
+
height: var(--select-arrow-height, var(--select-arrow-size, auto));
|
|
3613
3735
|
display: flex;
|
|
3614
3736
|
align-items: center;
|
|
3615
3737
|
justify-content: center;
|
|
@@ -3713,8 +3835,8 @@
|
|
|
3713
3835
|
}
|
|
3714
3836
|
|
|
3715
3837
|
.dropdown-arrow {
|
|
3716
|
-
width: var(--select-arrow-size,
|
|
3717
|
-
height: var(--select-arrow-size,
|
|
3838
|
+
width: var(--select-arrow-width, var(--select-arrow-size, 16px));
|
|
3839
|
+
height: var(--select-arrow-height, var(--select-arrow-size, 16px));
|
|
3718
3840
|
color: var(--select-arrow-color, var(--select-text-muted));
|
|
3719
3841
|
transition:
|
|
3720
3842
|
transform var(--select-transition-smooth),
|
|
@@ -3727,7 +3849,7 @@
|
|
|
3727
3849
|
}
|
|
3728
3850
|
|
|
3729
3851
|
.dropdown-arrow-container:hover .dropdown-arrow {
|
|
3730
|
-
color: var(--select-arrow-hover
|
|
3852
|
+
color: var(--select-arrow-hover, var(--select-arrow-hover-color, #667eea));
|
|
3731
3853
|
}
|
|
3732
3854
|
|
|
3733
3855
|
.dropdown-arrow.open {
|
|
@@ -4391,7 +4513,8 @@
|
|
|
4391
4513
|
:host-context([darkmode]) .group-header,
|
|
4392
4514
|
:host-context([data-theme="dark"]) .group-header,
|
|
4393
4515
|
:host-context([theme="dark"]) .group-header {
|
|
4394
|
-
|
|
4516
|
+
color: var(--select-dark-group-header-color, var(--select-group-header-color, inherit));
|
|
4517
|
+
background: var(--select-dark-group-header-bg, var(--select-group-header-bg, #1a1a2e));
|
|
4395
4518
|
border-bottom: var(--select-group-header-border-bottom, 1px solid rgba(255, 255, 255, 0.08));
|
|
4396
4519
|
box-shadow: var(--select-group-header-shadow, 0 1px 2px rgba(0, 0, 0, 0.3));
|
|
4397
4520
|
}
|
|
@@ -4884,6 +5007,41 @@
|
|
|
4884
5007
|
this._perfMeasure('smilodon-search-to-render', 'smilodon-search-input-last', 'smilodon-search-render-complete');
|
|
4885
5008
|
}
|
|
4886
5009
|
}
|
|
5010
|
+
/**
|
|
5011
|
+
* Filter items by search query (optimized hot path)
|
|
5012
|
+
* Uses for-loop with hoisted invariants for better performance
|
|
5013
|
+
*/
|
|
5014
|
+
_filterItemsByQuery(items, query) {
|
|
5015
|
+
// Early return for empty query
|
|
5016
|
+
if (!query?.trim())
|
|
5017
|
+
return items;
|
|
5018
|
+
// PERF: Hoist invariants outside loop
|
|
5019
|
+
const lowerQuery = query.toLowerCase().trim();
|
|
5020
|
+
const getLabelFn = this._config.serverSide.getLabelFromItem
|
|
5021
|
+
?? ((item) => item?.label ?? item?.text ?? String(item));
|
|
5022
|
+
const results = [];
|
|
5023
|
+
const len = items.length;
|
|
5024
|
+
// PERF: for-loop instead of filter (no closure allocation)
|
|
5025
|
+
for (let i = 0; i < len; i++) {
|
|
5026
|
+
const item = items[i];
|
|
5027
|
+
if (item == null)
|
|
5028
|
+
continue;
|
|
5029
|
+
try {
|
|
5030
|
+
const label = getLabelFn(item);
|
|
5031
|
+
if (label == null)
|
|
5032
|
+
continue;
|
|
5033
|
+
const labelStr = String(label).toLowerCase();
|
|
5034
|
+
if (labelStr.includes(lowerQuery)) {
|
|
5035
|
+
results.push(item);
|
|
5036
|
+
}
|
|
5037
|
+
}
|
|
5038
|
+
catch (e) {
|
|
5039
|
+
// Silent fail for robustness with external data
|
|
5040
|
+
continue;
|
|
5041
|
+
}
|
|
5042
|
+
}
|
|
5043
|
+
return results;
|
|
5044
|
+
}
|
|
4887
5045
|
_handleSearch(query) {
|
|
4888
5046
|
this._state.searchQuery = query;
|
|
4889
5047
|
this._syncClearControlState();
|
|
@@ -4909,25 +5067,12 @@
|
|
|
4909
5067
|
// Filter and render options immediately
|
|
4910
5068
|
this._renderOptions();
|
|
4911
5069
|
}
|
|
4912
|
-
//
|
|
4913
|
-
const
|
|
4914
|
-
// FIX: Do not trim query to allow searching for phrases with spaces
|
|
4915
|
-
const searchQuery = query.toLowerCase();
|
|
4916
|
-
const filteredItems = searchQuery
|
|
4917
|
-
? this._state.loadedItems.filter((item) => {
|
|
4918
|
-
try {
|
|
4919
|
-
const label = String(getLabel(item)).toLowerCase();
|
|
4920
|
-
// Match the entire search phrase
|
|
4921
|
-
return label.includes(searchQuery);
|
|
4922
|
-
}
|
|
4923
|
-
catch (e) {
|
|
4924
|
-
return false;
|
|
4925
|
-
}
|
|
4926
|
-
})
|
|
4927
|
-
: this._state.loadedItems;
|
|
5070
|
+
// PERF: Use optimized filter function
|
|
5071
|
+
const filteredItems = this._filterItemsByQuery(this._state.loadedItems, query);
|
|
4928
5072
|
const count = filteredItems.length;
|
|
4929
5073
|
// Announce search results for accessibility
|
|
4930
|
-
|
|
5074
|
+
const trimmedQuery = query.trim();
|
|
5075
|
+
if (trimmedQuery) {
|
|
4931
5076
|
this._announce(`${count} result${count !== 1 ? 's' : ''} found for "${query}"`);
|
|
4932
5077
|
}
|
|
4933
5078
|
// Only notify if query or result count changed to prevent infinite loops
|
|
@@ -5776,7 +5921,7 @@
|
|
|
5776
5921
|
this._state.selectedIndices.clear();
|
|
5777
5922
|
this._state.selectedItems.clear();
|
|
5778
5923
|
this._state.loadedItems.forEach((item, index) => {
|
|
5779
|
-
if (values
|
|
5924
|
+
if (arrayIncludesValue(values, getValue(item)) && !this._isOptionSelectionBlocked(item)) {
|
|
5780
5925
|
this._state.selectedIndices.add(index);
|
|
5781
5926
|
this._state.selectedItems.set(index, item);
|
|
5782
5927
|
}
|
|
@@ -5887,7 +6032,13 @@
|
|
|
5887
6032
|
this._clearControl.setAttribute('aria-label', this._config.clearControl.ariaLabel || 'Clear selection and search');
|
|
5888
6033
|
}
|
|
5889
6034
|
if (this._clearControlIcon) {
|
|
5890
|
-
|
|
6035
|
+
// Use config icon if provided, otherwise default SVG
|
|
6036
|
+
if (this._config.clearControl.icon) {
|
|
6037
|
+
this._clearControlIcon.textContent = this._config.clearControl.icon;
|
|
6038
|
+
}
|
|
6039
|
+
else {
|
|
6040
|
+
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>`;
|
|
6041
|
+
}
|
|
5891
6042
|
}
|
|
5892
6043
|
this._syncStyleConfigVariables();
|
|
5893
6044
|
if (this._dropdown) {
|
|
@@ -5898,19 +6049,30 @@
|
|
|
5898
6049
|
this._dropdown.removeAttribute('aria-multiselectable');
|
|
5899
6050
|
}
|
|
5900
6051
|
}
|
|
5901
|
-
this.
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
6052
|
+
if (this.isConnected) {
|
|
6053
|
+
this._syncDirectionConfig();
|
|
6054
|
+
this._syncInputContainerMode();
|
|
6055
|
+
this._syncMultiSelectDisplayConfig();
|
|
6056
|
+
this._syncDropdownPlacement();
|
|
6057
|
+
// Re-initialize observers in case infinite scroll was enabled/disabled
|
|
6058
|
+
this._initializeObservers();
|
|
6059
|
+
this._syncClearControlState();
|
|
6060
|
+
this._updateInputDisplay();
|
|
6061
|
+
this._renderOptions();
|
|
6062
|
+
}
|
|
6063
|
+
else {
|
|
6064
|
+
this._syncInputContainerMode();
|
|
6065
|
+
this._syncMultiSelectDisplayConfig();
|
|
6066
|
+
this._syncClearControlState();
|
|
6067
|
+
this._updateInputDisplay();
|
|
6068
|
+
}
|
|
5910
6069
|
}
|
|
5911
6070
|
_mergeConfig(target, source) {
|
|
5912
6071
|
const result = { ...target };
|
|
5913
|
-
|
|
6072
|
+
// PERF: Avoid for...in, use Object.keys for predictable iteration
|
|
6073
|
+
const keys = Object.keys(source);
|
|
6074
|
+
for (let i = 0; i < keys.length; i++) {
|
|
6075
|
+
const key = keys[i];
|
|
5914
6076
|
if (!Object.prototype.hasOwnProperty.call(source, key))
|
|
5915
6077
|
continue;
|
|
5916
6078
|
const sourceValue = source[key];
|
|
@@ -6252,6 +6414,9 @@
|
|
|
6252
6414
|
this._handleOptionRemove(targetIndex);
|
|
6253
6415
|
});
|
|
6254
6416
|
targetContainer.appendChild(option);
|
|
6417
|
+
if (option instanceof SelectOption) {
|
|
6418
|
+
option.ensureRendered();
|
|
6419
|
+
}
|
|
6255
6420
|
}
|
|
6256
6421
|
_normalizeCustomOptionElement(element, meta) {
|
|
6257
6422
|
const optionEl = element instanceof HTMLElement ? element : document.createElement('div');
|
|
@@ -6428,6 +6593,58 @@
|
|
|
6428
6593
|
this.supportsWorkers = false;
|
|
6429
6594
|
this.supportsSharedArrayBuffer = false;
|
|
6430
6595
|
this.nextId = 0;
|
|
6596
|
+
/**
|
|
6597
|
+
* Operation handlers for fallback execution
|
|
6598
|
+
*/
|
|
6599
|
+
this._fallbackOperations = {
|
|
6600
|
+
'transform': (payload) => {
|
|
6601
|
+
const { items, transformer } = payload;
|
|
6602
|
+
const fn = new Function('item', 'index', `return (${transformer})(item, index)`);
|
|
6603
|
+
return items.map((item, i) => fn(item, i));
|
|
6604
|
+
},
|
|
6605
|
+
'search': (payload) => {
|
|
6606
|
+
const { items, query, fuzzy } = payload;
|
|
6607
|
+
const lowerQuery = query.toLowerCase();
|
|
6608
|
+
const results = [];
|
|
6609
|
+
// Use for-loop instead of forEach for better performance (no closure allocation)
|
|
6610
|
+
for (let index = 0; index < items.length; index++) {
|
|
6611
|
+
const item = items[index];
|
|
6612
|
+
// PERF: Check for label/value properties first before converting entire object
|
|
6613
|
+
const itemAny = item;
|
|
6614
|
+
const itemText = itemAny?.label ?? itemAny?.value ?? item;
|
|
6615
|
+
const itemStr = String(itemText).toLowerCase();
|
|
6616
|
+
if (fuzzy) {
|
|
6617
|
+
// Simple fuzzy match - check if all query chars appear in order
|
|
6618
|
+
let queryIndex = 0;
|
|
6619
|
+
for (let i = 0; i < itemStr.length && queryIndex < lowerQuery.length; i++) {
|
|
6620
|
+
if (itemStr[i] === lowerQuery[queryIndex]) {
|
|
6621
|
+
queryIndex++;
|
|
6622
|
+
}
|
|
6623
|
+
}
|
|
6624
|
+
if (queryIndex === lowerQuery.length) {
|
|
6625
|
+
results.push({ item, index });
|
|
6626
|
+
}
|
|
6627
|
+
}
|
|
6628
|
+
else {
|
|
6629
|
+
// Exact substring match
|
|
6630
|
+
if (itemStr.includes(lowerQuery)) {
|
|
6631
|
+
results.push({ item, index });
|
|
6632
|
+
}
|
|
6633
|
+
}
|
|
6634
|
+
}
|
|
6635
|
+
return results;
|
|
6636
|
+
},
|
|
6637
|
+
'filter': (payload) => {
|
|
6638
|
+
const { items, predicate } = payload;
|
|
6639
|
+
const fn = new Function('item', 'index', `return (${predicate})(item, index)`);
|
|
6640
|
+
return items.filter((item, i) => fn(item, i));
|
|
6641
|
+
},
|
|
6642
|
+
'sort': (payload) => {
|
|
6643
|
+
const { items, comparator } = payload;
|
|
6644
|
+
const fn = new Function('a', 'b', `return (${comparator})(a, b)`);
|
|
6645
|
+
return [...items].sort(fn);
|
|
6646
|
+
},
|
|
6647
|
+
};
|
|
6431
6648
|
this.detectFeatures();
|
|
6432
6649
|
this.initWorker();
|
|
6433
6650
|
}
|
|
@@ -6469,27 +6686,23 @@
|
|
|
6469
6686
|
const start = performance.now();
|
|
6470
6687
|
const { id, type, payload } = e.data;
|
|
6471
6688
|
|
|
6689
|
+
// Lookup object for O(1) operation dispatch
|
|
6690
|
+
const operations = {
|
|
6691
|
+
'transform': handleTransform,
|
|
6692
|
+
'search': handleSearch,
|
|
6693
|
+
'filter': handleFilter,
|
|
6694
|
+
'sort': handleSort,
|
|
6695
|
+
};
|
|
6696
|
+
|
|
6472
6697
|
try {
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
case 'transform':
|
|
6477
|
-
result = handleTransform(payload);
|
|
6478
|
-
break;
|
|
6479
|
-
case 'search':
|
|
6480
|
-
result = handleSearch(payload);
|
|
6481
|
-
break;
|
|
6482
|
-
case 'filter':
|
|
6483
|
-
result = handleFilter(payload);
|
|
6484
|
-
break;
|
|
6485
|
-
case 'sort':
|
|
6486
|
-
result = handleSort(payload);
|
|
6487
|
-
break;
|
|
6488
|
-
default:
|
|
6489
|
-
throw new Error('Unknown operation: ' + type);
|
|
6698
|
+
const handler = operations[type];
|
|
6699
|
+
if (!handler) {
|
|
6700
|
+
throw new Error('Unknown operation: ' + type);
|
|
6490
6701
|
}
|
|
6491
6702
|
|
|
6703
|
+
const result = handler(payload);
|
|
6492
6704
|
const duration = performance.now() - start;
|
|
6705
|
+
|
|
6493
6706
|
self.postMessage({
|
|
6494
6707
|
id,
|
|
6495
6708
|
success: true,
|
|
@@ -6621,53 +6834,11 @@
|
|
|
6621
6834
|
* Fallback to main thread execution
|
|
6622
6835
|
*/
|
|
6623
6836
|
async executeFallback(type, payload) {
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
const { items, transformer } = payload;
|
|
6628
|
-
const fn = new Function('item', 'index', `return (${transformer})(item, index)`);
|
|
6629
|
-
return items.map((item, i) => fn(item, i));
|
|
6630
|
-
}
|
|
6631
|
-
case 'search': {
|
|
6632
|
-
const { items, query, fuzzy } = payload;
|
|
6633
|
-
const lowerQuery = query.toLowerCase();
|
|
6634
|
-
const results = [];
|
|
6635
|
-
items.forEach((item, index) => {
|
|
6636
|
-
const itemStr = String(item).toLowerCase();
|
|
6637
|
-
if (fuzzy) {
|
|
6638
|
-
// Simple fuzzy match - check if all query chars appear in order
|
|
6639
|
-
let queryIndex = 0;
|
|
6640
|
-
for (let i = 0; i < itemStr.length && queryIndex < lowerQuery.length; i++) {
|
|
6641
|
-
if (itemStr[i] === lowerQuery[queryIndex]) {
|
|
6642
|
-
queryIndex++;
|
|
6643
|
-
}
|
|
6644
|
-
}
|
|
6645
|
-
if (queryIndex === lowerQuery.length) {
|
|
6646
|
-
results.push({ item, index });
|
|
6647
|
-
}
|
|
6648
|
-
}
|
|
6649
|
-
else {
|
|
6650
|
-
// Exact substring match
|
|
6651
|
-
if (itemStr.includes(lowerQuery)) {
|
|
6652
|
-
results.push({ item, index });
|
|
6653
|
-
}
|
|
6654
|
-
}
|
|
6655
|
-
});
|
|
6656
|
-
return results;
|
|
6657
|
-
}
|
|
6658
|
-
case 'filter': {
|
|
6659
|
-
const { items, predicate } = payload;
|
|
6660
|
-
const fn = new Function('item', 'index', `return (${predicate})(item, index)`);
|
|
6661
|
-
return items.filter((item, i) => fn(item, i));
|
|
6662
|
-
}
|
|
6663
|
-
case 'sort': {
|
|
6664
|
-
const { items, comparator } = payload;
|
|
6665
|
-
const fn = new Function('a', 'b', `return (${comparator})(a, b)`);
|
|
6666
|
-
return [...items].sort(fn);
|
|
6667
|
-
}
|
|
6668
|
-
default:
|
|
6669
|
-
throw new Error(`Unknown operation: ${type}`);
|
|
6837
|
+
const handler = this._fallbackOperations[type];
|
|
6838
|
+
if (!handler) {
|
|
6839
|
+
throw new Error(`Unknown operation: ${type}`);
|
|
6670
6840
|
}
|
|
6841
|
+
return handler(payload);
|
|
6671
6842
|
}
|
|
6672
6843
|
/**
|
|
6673
6844
|
* Transform items with custom function
|
|
@@ -7431,6 +7602,8 @@
|
|
|
7431
7602
|
exports.WorkerManager = WorkerManager;
|
|
7432
7603
|
exports.applyClasses = applyClasses;
|
|
7433
7604
|
exports.applyDefaultTheme = applyDefaultTheme;
|
|
7605
|
+
exports.arrayIncludesValue = arrayIncludesValue;
|
|
7606
|
+
exports.arraysEqualByValue = arraysEqualByValue;
|
|
7434
7607
|
exports.configureSelect = configureSelect;
|
|
7435
7608
|
exports.containsSuspiciousPatterns = containsSuspiciousPatterns;
|
|
7436
7609
|
exports.createElement = createElement;
|
|
@@ -7460,6 +7633,7 @@
|
|
|
7460
7633
|
exports.shadowDOMStyles = shadowDOMStyles;
|
|
7461
7634
|
exports.toggleClass = toggleClass;
|
|
7462
7635
|
exports.validateTemplate = validateTemplate;
|
|
7636
|
+
exports.valuesEqual = valuesEqual;
|
|
7463
7637
|
exports.warnCSPViolation = warnCSPViolation;
|
|
7464
7638
|
|
|
7465
7639
|
}));
|